How to generate random password using PHP?
Strong password should be,
- At least eight characters long.
- Very good combination of letters, numbers, and special characters.
- Don't use dictionary words.
- Don't use your phone number,reverse order of your name,nick name,NIC number,Passport number, or mobile number.
- A good combination of simple and capital letters.
- Don't use characters or numbers only.
- Memorized easily without save it to a other media.
- Change your password periodically.
Don't use dictionary words or names as your password. Because it cause to a dictionary attack. Also it is important to keep separate password for your other e-mail or computer accounts.
When you make a password, you have to keep above guidelines in your mind. I f you use a strong password, it is difficult to break the password using automated computer programs. (robot programs) Working with web applications you may be always need to generate random passwords in PHP. Suppose you have a user registration form. After a user registration you have to assign a random password to his account and e-mail login details. So definitely you need to generate random passwords for this case. Following examples describe you how to generate multiple passwords using PHP.
View Live Demo - PHP Random Password Generator
1. How to create random passwords in PHP using numbers?
This example describe you to generate random password with numbers in PHP. Generated password contains integers 0 to 9. But be careful using numerical passwords because it can be break using automated computer programs.
<?php
function generatePasswordsUsingNumbers($length){
$numbers='0123456789';
$password_characters = str_split($numbers);
$password='';
for($i=0;$i<$length;$i++){
$password.=$password_characters[rand(0,count($password_characters)-1)];
}
return $password;
}
echo generatePasswordsUsingNumbers(8);
?>
2. How to create random passwords in PHP using alphabetic characters?
Sometimes you may need to create passwords using alphabetic characters. Bellow function explains make random password in php. Populated password contains a random set of simple and capital letters. You can change the length of the password.
<?php
functiongeneratePasswordsUsingCharacters($passwordLength){
$letters='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$password_characters = str_split($letters);
$password='';
for($i=0;$i<$passwordLength;$i++){
$password.=$password_characters[rand(0,count($password_characters)-1)];
}
return $password;
}
echo generatePasswordsUsingCharacters(8);
?>
3. How to create random passwords in PHP using alphabetic characters and numeric characters?
When you need php random passwords with a combination of letters and numbers, use bellow function to create passwords. You can make strong passwords using this method. You can pass the parameter "password length" to change the length of the created password. Use higher value to make it strong.
<?php
functiongeneratePasswordsUsingCharactersAndNumbers($passwordLength){
$characters='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$password_characters = str_split($characters);
$password='';
for($i=0;$i<$passwordLength;$i++){
$password.=$password_characters[rand(0,count($password_characters)-1)];
}
return $password;
}
echo generatePasswordsUsingCharactersAndNumbers(8);
?>
4. PHP class for generate multiple random passwords
This is a special php class that use to generate random passwords. You can generate any kind of passwords using this. It can create various types of passwords including numbers,characters, and special characters. Also you can manually set the special characters. You can generate unbreakable php passwords using this class. Please note before you save to password to the database, convert it to a hash value using one way encryption function. Do not save password directly.
<?php
/*
Copyright By http://www.latestcode.net
*/
class PHP_Password_Generator{
public $password_length;
public $password;
private $numbers;
private $alphabetic_chars;
private $special_chars;
private $password_type;
public function __construct($type){
$this->password_type = $type;
$this->numbers='0123456789';
$this->alphabetic_chars='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$this->special_chars='@#$%&!';
}
/*
Generate Password
*/
public function generate_password($length=8){
$this->password_length = ($length<1?8:$length);
$this->password='';
switch($this->password_type){
case 1:{//Numbers Only
$password_characters = $this->numbers;
}break;
case 2:{//Alphabetic CHaracters Only
$password_characters = $this->alphabetic_chars;
}break;
case 3:{//Numbers And Letters Only
$password_characters = $this->numbers.$this->alphabetic_chars;
}break;
case 4:{//Numbers,Letters, and Special Characters
$password_characters = $this->numbers.$this->alphabetic_chars.$this->special_chars;
}break;
default:{//Letters
$password_characters = $this->alphabetic_chars;
}break;
}
$password_characters = str_split($password_characters);
shuffle($password_characters);
for($i=0;$i<$this->password_length;$i++){
$this->password.=$password_characters[rand(0,count($password_characters)-1)];
}
return $this->password;
}
/*
Add custom special characters to the password
*/
public function set_special_characters($special_chars){
$this->special_chars = $special_chars;
}
}
//Example 1:
$pwd = new PHP_Password_Generator(4);//Generate password with numbers,letters, and special characters
echo $pwd->generate_password(10);//specify password length
//Example 2:
$pwd = new PHP_Password_Generator(4);
$pwd->set_special_characters('@#$%^&*');//Set custom special characters
echo $pwd->generate_password(10);
//Example 3:
$pwd = new PHP_Password_Generator(1);//Password will contain numbers
echo $pwd->generate_password(10);
//Example 4:
$pwd = new PHP_Password_Generator(4);//Make list of passwords
for($x=0;$x<5;$x++){
echo $pwd->generate_password(10).'<br/>';
}
?>
54 comments:
Kem xoài được khá nhiều người yêu thích vì nó ít ngọt hơn các loại kem khác. Dưới đây là 3 cach lam kem xoai
Sau đây chuyên mục món ăn ngon xin hướng dẫn cách làm sữa chua từ sữa tươi, cách làm sữa chua từ sữa đặc ngon tại nhà. Với những hướng dẫn chi tiết sau. Mong rằng sẽ cung cấp cho bạn được cách làm sữa chua ngon
Đứa trẻ nào cũng bị “hút hồn” bởi “ma lực” của kem chuối, ngay cả người lớn cũng vậy. Vậy cách làm kem chuối thơm ngon như thế nào để ôtủ lạnh nhà bạn luôn có món kem chuối khoái khẩu?Sau đây chúng tôi chia sẻ cách làm kem chuối
Không chỉ là một loại dầu đa năng, phát huy tốt tác dụng trong việc chăm sóc sức khỏe, chế biến các món ăn hàng ngày, dầu dừa còn có công dụng làm đẹp da rất hiệu quả mà không phải ai cũng biết. Chính vì vậy, trong thời gian gần đây, rất nhiều chị em trở nên “cuồng” loại mỹ phẩm tự nhiên này nhờ hiệu quả làm đẹp vượt trội mà nó mang lại. Vậy dưỡng da bằng dầu dừa
Tác dụng của dầu dừa trong việc làm đẹp rất tuyệt với và được rất nhiều chị em phụ nữ tin dùng. Tuy nhiên, không phải ai cũng nắm được cách làm và tác dụng của loại thần dược này, hãy cùng khám phá cách làm đẹp từ dầu dừa
Dầu dừa là một loại thảo dược vô cùng tốt cho sức khóe,cũng như công cuộc làm đep của chị em phụ nữ.Nó được làm từ hoàn toàn tự nhiên,không độc hại,nhưng cách dùng dầu dừa
Dầu dừa là dược phẩm rất tuyệt vời để làm đẹp da, hạn chế rạn da, nám da hay tắm trắng. Bạn hoàn toàn có thể tự làm dầu dừa tại nhà để có được dầu dừa nguyên chất cho nhu cầu của mình. Chúng tôi sẽ hướng dẫn 2 cach lam dau dua
try this simple code : http://www.sanwebcorner.com/2017/08/generate-password-to-textbox-using-php.html
VERY INFORMATIVE BLOG. KEEP SHARING SUCH A GOOD ARTICLES.
Best Software Company in USA | Austere Technology Solutions
Nice blog with excellent information. Thank you, keep sharing.
Best Software Security Services | Austere Technology Solutions
Really great blog.
Best Cloud Services | Austere Technology Solutions
Very good informative article. Thanks for sharing such nice article, keep on updating such good articles.
Best Internet of Things Services | Best IOT Services | Austere Technology Solutions
Needed to compose one little word yet thanks for the suggestions that you are contributed here, would like to read this blog regularly to get more updates...
Best Online Software Training Institute | PHP Training
Excellent informative blog, keep for sharing.
Best System Integration services | Massil Technologies
Article found very useful, thank you for sharing…
Php Training | Software Training courses in hyderabad
best article with nice information thank you
DevOps Training in Hyderabad
Salesforce Training in Hyderabad
SAP ABAP Online Training
SEO Training in Hyderabad
It's really an Excellent post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog. Thanks for sharing...
Selenium online training
Selenium certification training
Selenium online course
Selenium training course
GOOD...
internships in chennai
winter internship mechanical engineering
internship for aeronautical engineering students in india 2019
kaashiv
list of architectural firms in chennai for internship
paid internships in pune for computer science students
diploma final year project topics for information technology
internship
data science internship report
inplant training
Thanks for sharing this interesting information. I am so happy to read this. I love reading this type of blog, again thank you for sharing.
Data Science Training in Hyderabad
Hadoop Training in Hyderabad
Java Training in Hyderabad
Python online Training in Hyderabad
Tableau online Training in Hyderabad
Blockchain online Training in Hyderabad
informatica online Training in Hyderabad
devops online Training
Thanks for sharing it.I got Very valuable information from your blog.your post is really very Informative.I’m satisfied with the information that you provide for me.Nice post. By reading your blog, i get inspired and this provides some useful information.
Php training in pune at 3ri Technologies
Your good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.
Regards : Selenium Training Institute in Pune
Really Good article.provided a helpful information.keep updating...
Regards : Best SAP FICO Training in Pune With Placement
I liked your article, Thanks for sharing,
Best Dot Net Institute in Pune
Best Market Research Institute in Pune
Best Data Science Institute in Pune
Best PHP Institute in Pune
Best Software Testing Institute in Pune
Best Clinical Research Courses in Pune
Best Digital Marketing Institute in Pune
Best Training Institute in Pune
Really awesome blog!!! I finally found a great post here.I really enjoyed reading this article. Thanks for sharing valuable information.
Register for a free Online Demo Classes
Data Science Training Institute in Pune
Best Python Online Training
Online AWS Training
Online Data Science Training
Thank you for sharing this useful article with us. This blog is a very helpful to me in future. Keep sharing informative articles with us.
https://www.ahmedabadcomputereducation.com/course/php-training-course/
I like your post. It is very useful to all.
In this post having more useful information and improve our knowledge. Can you share more valuable information present Technology?
Devops Training in Gurgaon
Docker Kubernetes training in Gurgaon
Thank you for sharing this useful article with us. This blog is a very helpful to me in future. Keep sharing informative articles with us.
https://www.paygonline.site/
Thank you for sharing this useful article. This blog is a very helpful to me. Keep sharing informative articles with us.
https://www.france-collectivites.fr/
Thank you for sharing this useful article with us. This blog is a very helpful to me. Keep sharing informative articles with us.
https://www.sdsfin.in/services/project-finance-consultants-in-ahmedabad/
Excellent post and I am very happy to read this blog. Keep doing...!
Primavera Training in Chennai
Embedded System Course in Chennai
Embedded Training in Coimbatore
Primavera Course in Chennai
Nice post...! This is the best explanation for this topic and a good job, keep doing...
Ui Ux Design Course in Chennai
UiPath Online Training
UiPath Training in Chennai
UiPath Training in Bangalore
Excellent blog..! This is the best for my development and keeps updating...
JMeter Training in Chennai
Appium Training in Chennai
Appium Online Training
Appium Training in Coimbatore
JMeter Online Training
It's a very informative blog and I am exactly looking for this type of blog. Thank you for sharing this beautiful blog.
https://superurecoat.com/titanium-iso-propoxide/
Thank you for sharing valuable information with us. Exactly, I am looking for this types of blog.
Loan Against Property
Loan Against Property in Vadodara
Loan Against Property in Ahmedabad
Loan Against Property Companies
Loan Against Property Interest Rate
Great information. Really helpful.
Such a great blog. Absolutely stunning. Really helpful.
Such a cool blog.
This is a really informative blog.
Thank You for sharing such a nice article.
i Liked your article. Thanks for sharing.
Very Informative. Nice Blog.
I am really happy to say it’s an interesting post to read. I learn new information from your article; you are doing a great job. Keep it up…
Manal testing Training in Gurgaon
Selenium Training in Gurgaon
Cucumber Training in Gurgaon
Microservices Testing Training in Gurgaon
This is an interesting post!!!
The information is very very useful.
Thank you for sharing this Article.This would really help me in the future
Thank you for the great information. Keep Sharing it!
https://saroitapes.com/
Out of 10 every 8 people in the world has been suffered from severe attack of back pain during their life time. Back pain is a symptoms rather than disease. Doctor finds out the cause of back pain and treats accordingly. Back pain is pain felt in the back that usually originates from the muscles, nerves, bones, joints or other structures in the spine.
WHAT ARE CAUSES OF BACK PAIN?
There are many causes of back pain. Long standing degeneration (wearing away) of the vertebrae and the intervertebral disc is the primary cause behind this disorder.
Back Pain Treatment in Ahmedabad
Thanks for sharing informative article.
https://web30india.com/
Great Article. Really interesting.
Clinical Research Courses
Thats very interesting.
Thanks for crafting this beautiful information. I’m thankful and humbled to you. This is the best blog I have ever read. I’m going to make sure that I will share. Rubix Market Research
Great Post! it is very helpful for me and all for those who want to learn.
Clinical Research Courses in Pune
Excellent Article. Thank you for sharing!
https://www.ahmedabadcomputereducation.com/
https://www.ahmedabadcomputereducation.com/course/live-project-training-in-asp-net/
https://www.ahmedabadcomputereducation.com/course/live-project-training-in-ios/
https://www.ahmedabadcomputereducation.com/course/live-project-training-in-java/
https://www.ahmedabadcomputereducation.com/course/live-project-training-in-android/
https://www.ahmedabadcomputereducation.com/course/live-project-training-in-php/
https://www.ahmedabadcomputereducation.com/course/live-project-training-in-python/
Excellent Article. Kepp Sharing with us!
PHP Web Development
Web Application Development
Cloud Web Application
Web Application Security Expertise
Front End Development & UX Design
Multi Platform Integration Services
Hire PHP Programmer
I am really happy to say it’s an interesting post to read . I learn new information from your article , you are doing a great job . Keep it up
Devops Training in Hyderabad
Hadoop Training in Hyderabad
Python Training in Hyderabad
Tableau Training in Hyderabad
Selenium Training in Hyderabad
informatica Training in Hyderabad
datastage Training in Hyderabad
Android Mobile App Development in Ahmedabad
Web 3.0 India is the most trusted Web3 Blockchain Development and NFT Development Company in USA. We also provides ICO, STO development for cryptocurrency.
https://web30india.com/
Thank you very much for the post. Very informative!
https://marketreportsinsights.com/de/industry-forecast/precision-farming-tools-market-2022-128364
This article has helped me a lot with some good solutions to my queries.
https://marketreportsinsights.com/de/industry-forecast/inherently-dissipative-polymer-market-2022-128264
Thank you for your informative blog.
We appreciate you sharing this informative post with us. Continue providing us with helpful content.
https://www.ownuxglobal.com/
Post a Comment