function generatepassword($plength) {
if(!is_numeric($plength) || $plength <= 0) {
$plength = 8;
}
if($plength > 32) {
$plength = 32;
}
$chars = ‘abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789’;
mt_srand(microtime() * 1000000);
for($i = 0; $i < $plength; $i++) {
$key = mt_rand(0,strlen($chars)-1);
$pwd = $pwd . $chars{$key};
}
for($i = 0; $i < $plength; $i++) {
$key1 = mt_rand(0,strlen($pwd)-1);
$key2 = mt_rand(0,strlen($pwd)-1);
$tmp = $pwd{$key1};
$pwd{$key1} = $pwd{$key2};
$pwd{$key2} = $tmp;
}
return $pwd;
}
Kullanımı:
echo generatepassword(7); //7 haneli şifre üretir