note 13427 modified in function.rand.php by philip
| From: | philip@php.net | Date: | Sun, 26 Aug 2001 11:24:00 +0000 |
| Subject: | note 13427 modified in function.rand.php by philip | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-17166@lists.php.net to get a copy of this message | ||
Generates a password using a random word (from a list you provide) and appends a random number. Not
ideal for uber-security but the idea works.
Also ouputs rAndOm CasE :
$words = array ('bread', 'apple', 'mississippi', 'globe',
'kind', 'good', 'life');
function genPassword ($words, $min_num = 101, $max_num = 99999, $sep = NULL)
{
global $seed;
$word = '';
$size = sizeof($words) - 1;
if (!empty($seed)) {
mt_srand ((double) microtime()*10000000);
$seed = TRUE;
}
$raw_word = $words[mt_rand(0,$size)];
for($a=0; $a <= strlen($raw_word); $a++) {
$case_func = mt_rand(0,1) ? 'strtoupper' : 'strtolower';
$word .= $case_func($raw_word{$a});
}
return $word . $sep . mt_rand($min_num,$max_num);
}
http://www.php.net/manual/en/function.rand.php.php