note 33156 deleted from function.rand by aidan
| From: | aidan@php.net | Date: | Sat, 11 Sep 2004 07:42:43 +0000 |
| Subject: | note 33156 deleted from function.rand by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-76452@lists.php.net to get a copy of this message | ||
Note Submitter: admin at gwdn dot com
----
Viewing the comments and the random password scripts listed i figured i'd show my simple but
effective password generator.
function ranpass($len = "8"){
$pass = NULL;
for($i=0; $i<$len; $i++) {
$char = chr(rand(48,122));
while (!ereg("[a-zA-Z0-9]", $char)){
if($char == $lchar) continue;
$char = chr(rand(48,90));
}
$pass .= $char;
$lchar = $char;
}
return $pass;
}
usage:
$password = ranpass(); // Will generate a 8 charater password
$password = ranpass(6); // Will generate a 6 character password
The password will not repeat two characters in a row.
For example you wont recieve like kEg64AA
but you might recieve kEg64Aa.
I tested up to 9999 characters and it went fast even with a number that big.