note 26541 added to function.rand
| From: | clev at cleverone dot com | Date: | Mon, 04 Nov 2002 03:25:02 +0000 |
| Subject: | note 26541 added to function.rand | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-38939@lists.php.net to get a copy of this message | ||
Here's a function to create a random (case sensitive)password for the length you supply ...
function RandomPassword( $passwordLength ) {
$password = "";
for ($index = 1; $index <= $passwordLength; $index++) {
// Pick random number between 1 and 62
$randomNumber = rand(1, 62);
// Select random character based on mapping.
if ($randomNumber < 11)
$password .= Chr($randomNumber + 48 - 1); // [ 1,10] => [0,9]
else if ($randomNumber < 37)
$password .= Chr($randomNumber + 65 - 10); // [11,36] => [A,Z]
else
$password .= Chr($randomNumber + 97 - 36); // [37,62] => [a,z]
}
return $password;
}
Hope this helps.
Clev
--
http://www.php.net/manual/en/function.rand.php
http://master.php.net/manage/user-notes.php?action=edit+26541
http://master.php.net/manage/user-notes.php?action=delete+26541
http://master.php.net/manage/user-notes.php?action=reject+26541