Page 1 of 1

Random PAssword Generation

Posted: Sun Aug 15, 2004 11:49 am
by dwfait
Hi. How would i generate a long radnom password, consisting of numbers and letters?

Posted: Sun Aug 15, 2004 12:09 pm
by anjanesh

Code: Select all

<?php
$strList=array();
for ($i=48;$i<=57;$i++) $strList[]=chr($i);
for ($i=65;$i<=90;$i++) $strList[]=chr($i);
for ($i=97;$i<=122;$i++) $strList[]=chr($i);
$Pass="";
for ($i=0;$i<50;$i++) $Pass.=$strList[rand(0,count($strList)-1)];
echo $Pass;
?>

Posted: Sun Aug 15, 2004 12:20 pm
by dwfait
Thanks. Also, im saving my passwords as an MD5 value in my database. If one of the users were to lose their passwords, how would i revert their password from MD5 to their normal password to email it to them?

Posted: Sun Aug 15, 2004 12:29 pm
by anjanesh
You cannot get back MD5 values back. Either you have to generate a new password and mail or use mcrypt functions instead where you can encryt and decrypt using your own key.
http://www.php.net/manual/en/ref.mcrypt.php