note 75029 added to function.mt-rand
| From: | PaulNolasco at osu1 dot php dot net | Date: | Wed, 09 May 2007 07:45:49 +0000 |
| Subject: | note 75029 added to function.mt-rand | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-126356@lists.php.net to get a copy of this message | ||
Here's a more user friendly password generator. You want to make it easier for the user to
enter the new password.
Output:
- First character is capitalize
- Rest of the characters are either number or letters (lowercase)
You can change the probability depending on your taste. Also by default it generates a 8-character
long password.
<?php
function genPassword($length=8)
{
# first character is capitalize
$pass = chr(mt_rand(65,90)); // A-Z
# rest are either 0-9 or a-z
for($k=0; $k < $length - 1; $k++)
{
$probab = mt_rand(1,10);
if($probab <= 8) // a-z probability is 80%
$pass .= chr(mt_rand(97,122));
else // 0-9 probability is 20%
$pass .= chr(mt_rand(48, 57));
}
return $pass;
}
?>
----
Server IP: 69.39.81.135
Probable Submitter: 69.153.49.74
----
Manual Page -- http://www.php.net/manual/en/function.mt-rand.php
Edit -- https://master.php.net/note/edit/75029
Del: integrated -- https://master.php.net/note/delete/75029/integrated
Del: useless -- https://master.php.net/note/delete/75029/useless
Del: bad code -- https://master.php.net/note/delete/75029/bad+code
Del: spam -- https://master.php.net/note/delete/75029/spam
Del: non-english -- https://master.php.net/note/delete/75029/non-english
Del: in docs -- https://master.php.net/note/delete/75029/in+docs
Del: other reasons-- https://master.php.net/note/delete/75029
Reject -- https://master.php.net/note/reject/75029
Search -- https://master.php.net/manage/user-notes.php