note 63455 deleted from function.rand by bjori
| From: | bjori@php.net | Date: | Wed, 22 Mar 2006 17:51:39 +0000 |
| Subject: | note 63455 deleted from function.rand by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-106285@lists.php.net to get a copy of this message | ||
Note Submitter: leetcrew <at> gamesite-cafe <dot> com
Reason: bad code
----
this code is very usefull if you are planning to have a "forgot password" or "lost
password" function on your website.
<?php
function generate($max_char=5)
{
# 61 possible characters
$possible_combinations = array (
'A', 'B', 'C', 'D', 'E', 'F',
'G', 'H', 'I', 'J', 'K', 'L',
'M', 'N', 'O',
'P', 'Q', 'R', 'S', 'T', 'U',
'V', 'W', 'X', 'Y', 'Z',
'a', 'b', 'c', 'd', 'e', 'f',
'g', 'h', 'i', 'j', 'k', 'l',
'm', 'n', 'o',
'p', 'q', 'r', 's', 't', 'u',
'v', 'w', 'x', 'y', 'z',
'0', '1', '2', '3', '4', '5',
'6', '7', '8', '9');
$generated_code = $possible_combinations[rand(0,61)];
for ( $i=5; $i<=$max_char; $i++)
{
$generated_code .= $possible_combinations[rand(0,61)];
}
$generated_code .= $possible_combinations[rand(52,61)];
$generated_code .= $possible_combinations[rand(52,61)];
$generated_code .= $possible_combinations[rand(52,61)];
return $generated_code;
}
?>