Sunday, December 30, 2012

PHP Random password generator

How to generate random password using PHP?

The bellow example shows you how to create random passwords in PHP
When you are talking about internet you can't forget security. Basically internet security depends on passwords. Why do you need passwords? Simply because protect your personal data from others. Passwords help you to keep your data secure. Without knowing the password anyone can't read or access your data. When we talking about passwords you have to consider the strength of the password.

Strong password should be,

  1. At least eight characters long.
  2. Very good combination of letters, numbers, and special characters.
  3. Don't use dictionary words.
  4. Don't use your phone number,reverse order of your name,nick name,NIC number,Passport number, or mobile number.
  5. A good combination of simple and capital letters.
  6. Don't use characters or numbers only.
  7. Memorized easily without save it to a other media.
  8. 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.

Complete source code for populate random password in PHP.

<?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.

Complete PHP source code for generate password with letters.

<?php
function
generatePasswordsUsingCharacters($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.

Copy and paste bellow code populate strong password in PHP

<?php
function
generatePasswordsUsingCharactersAndNumbers($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.

Example code for create multiple random password list using PHP.

<?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:

Unknown said...

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

Sandilyan said...

try this simple code : http://www.sanwebcorner.com/2017/08/generate-password-to-textbox-using-php.html

Austere said...

VERY INFORMATIVE BLOG. KEEP SHARING SUCH A GOOD ARTICLES.

Best Software Company in USA | Austere Technology Solutions

Unknown said...

Nice blog with excellent information. Thank you, keep sharing.

Best Software Security Services | Austere Technology Solutions

Deepika said...

Really great blog.

Best Cloud Services | Austere Technology Solutions

Austere said...

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

Anonymous said...

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

Deepika said...

Excellent informative blog, keep for sharing.

Best System Integration services | Massil Technologies

Sathyatech said...

Article found very useful, thank you for sharing…

Php Training | Software Training courses in hyderabad

jagadeesh said...

best article with nice information thank you
DevOps Training in Hyderabad
Salesforce Training in Hyderabad
SAP ABAP Online Training
SEO Training in Hyderabad

jothikumar said...

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

nash b said...

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

Data science said...

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

vijayshri said...

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

sam said...

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

3riTec said...

Really Good article.provided a helpful information.keep updating...
Regards : Best SAP FICO Training in Pune With Placement

My first blogs said...

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

Technogeekscs said...

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

ACE said...

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/

Amrita Bansal said...

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

Paygonline said...

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/

France Collectivities said...

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/

Livewell Hospital said...

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/

Aarav said...

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

Samit said...

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

Kayal said...

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

Super Urecoat said...

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/

Livewell Hospital said...

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

Noah Benz said...

Great information. Really helpful.

selena Benz said...

Such a great blog. Absolutely stunning. Really helpful.

shreya said...

Such a cool blog.

Noah Benz said...

This is a really informative blog.

Rohti said...

Thank You for sharing such a nice article.

Tejas said...

i Liked your article. Thanks for sharing.

Suri said...

Very Informative. Nice Blog.

Amrita Bansal said...

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

Tejas said...

This is an interesting post!!!

Raj said...

The information is very very useful.

Tiya said...

Thank you for sharing this Article.This would really help me in the future

Livewell Hospital said...

Thank you for the great information. Keep Sharing it!

https://saroitapes.com/

Unknown said...

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

Ekku2324@ said...

Thanks for sharing informative article.

https://web30india.com/

Clinical Research Courses said...

Great Article. Really interesting.
Clinical Research Courses

Shreya said...

Thats very interesting.

Anamika Singh said...

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

Clinical Research Training said...

Great Post! it is very helpful for me and all for those who want to learn.
Clinical Research Courses in Pune

Ekku2324@ said...

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/

Ekku2324@ said...

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

RS Trainings said...

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

hirededicatedresources said...

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/

marketreports said...

Thank you very much for the post. Very informative!
https://marketreportsinsights.com/de/industry-forecast/precision-farming-tools-market-2022-128364

marketreports said...

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

ankeeta said...

Thank you for your informative blog.

Anonymous said...

We appreciate you sharing this informative post with us. Continue providing us with helpful content.

https://www.ownuxglobal.com/