Infolinks

Breaking

Adsense

Thursday, April 28, 2016

RANDOM PASSWORD GENERATOR USING PHP

A random password generator is used to easily create a more secure and faster way to generate user passwords. If you want to create random passwords to hundreds or even thousands of users easily, then this program is suited for you. This will solve your problem in mass generation of password.

I will discuss the PHP code for you to easily understand it. $string="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";will create a variable $string with values from A-Z, a-z and 0-9. This is where we are going to draw our random password. $limit will serve as our stopper or the number of characters it will generate. In our example below, the limit is 10. In short, it will display ten (10) characters. You can change it base on your needs. Initialize values for $code as null, $limit as 10 and $i as 0. $code should be initialized if you are using the latest XAMPP or WAMP to avoid undefined index error. $i should be set to zero (0) and will served as the counter in our while loop.

In our loop, random numbers will be selected one at a time from numbers between 0 to 61. Since we are dealing with string, you have to remember that indexes start with 0 and they are used to access values in strings. That is why we need to generate numbers equivalent to string index between 0 to 61. Kindly refer on the image below for a clear illustration. Next is, access the string character using their index and store it in the variable $code and combine it with the previous selected character. $i++ to increment our counter from 0 to 1, next turn in loop is 2 and so on until it reaches 10 and then it will stop. Last is to display those random characters. 

PHP CODE FOR RANDOM PASSWORD GENERATOR

<?php
$string="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
$code="";
$limit=10;
$i=0;
while($i<=$limit)
{
$rand=rand(0,61);
$code.=$string[$rand];
$i++;
}
echo $code;
?>

OUTPUT FOR RANDOM PASSWORD GENERATOR


For questions, you can comment below and I’ll try to answer it. Thank you and God bless! Best of luck to all of you.

RANDOM PASSWORD GENERATOR USING PHP

No comments:

Post a Comment

Adbox