Generate Random Password

Are you designing a website where a user can register himself?

Do you want to help him generating a random password? Try this simple code….

<?php

function generatePassword($length=16)
{

$chars =”ABCDEFGHIJKLMNOPQRST
UVWXYZabcdefghijklmnopqrstuvwxyz1234567890″;//length:36
$final_rand=””;
for($i=0;$i<$length; $i++)
{
$final_rand .= $chars[ rand(0,strlen($chars)-1)];

}
return $final_rand;
}
?>

How To execute??

<?php

echo generatePassword(10);  //call the function….

?>

 

 

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s