Random password generator
Here’s a quick PHP function to generate a random password, usage:
genrand($password_length);
<?php
function genrand($len = 10) {
for ($i = 0; $i < 26; $i++) {
$str[$i] = chr($i+65);
}
unset($i);
for ($i = 26; $i < 52; $i++) {
$str[$i] = chr($i+71);
}
unset($i);
for ($i = 52; $i < 62; $i++) {
$str[$i] = $i-52;
}
unset($i);
mt_srand(microtime()*100000);
$retval = NULL;
for ($i = 1; $i <= $len; $i++) {
$random = mt_rand(0, count($str)-1);
$retval .= $str[$random];
}
unset($i);
return $retval;
}
?>
