note 43716 deleted from function.rand by tomsommer
| From: | tomsommer@php.net | Date: | Thu, 01 Jul 2004 15:21:29 +0000 |
| Subject: | note 43716 deleted from function.rand by tomsommer | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-72268@lists.php.net to get a copy of this message | ||
Note Submitter: lastlee@aol.com
----
I made a random password generator function that does not use strings, but with pretend strings
(that are much faster):
<?php
function rand_pass()
{
// Get the alphabet
for ($i = 97; $i <= 122; $i++)
{
$str[$i] = chr($i);
}
// Here we set $rand_str to $str[] with a random string
$rand_str = $str[rand(97, 122)];
$rand_str .= $str[rand(97, 122)];
$rand_str .= $str[rand(97, 122)];
// Get the numerals
for ($i = 48; $i <= 57; $i++)
{
$num[$i] = chr($i);
}
// Do the same as the strings here
$rand_num = $num[rand(48, 57)];
$rand_num .= $num[rand(48, 57)];
$rand_num .= $num[rand(48, 57)];
$rand_num .= $num[rand(48, 57)];
// Put it together with a nice, easier to remember format
$password = $rand_str . $rand_num;
return $password;
}
?>