Hi
I need a function that can generate a random password 10 alphanumeric (letters and numbers) characters long. Can anybody help?
Regards
Peter
here's one. It'a little rough, but it should do what you need.
mt_srand ((float) microtime() * 1000000); function passgen($length) { $charstring="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890"; $len = strlen($charstring); for($i=0;$i<$length;$i++) { $index = mt_rand(0,$len-1); $pass .= $charstring[$index]; } return($pass); }
<? srand(time());
$i=($QUERY_STRING)?ereg_replace("[^0-9]","",$QUERY_STRING):"10"; while($i--) { while(!ereg("[a-zA-Z0-9]",$chr=sprintf("%c",rand(48,127)))) ; echo $chr; } echo "\n";
?>
usage: file.php?num where num is a requested length of password