Pazar, Şubat 26, 2012

PHP: Generate a random password


function generatePassword($length=9, $strength=0) {
    srand((double)microtime()*1000000);
    $chars = 'abcdefghijklmnopqrstuvwxyz0123456789';
    if ($strength > 1) $chars .= 'ABDGHJLMNPQRSTVWXZ';
    if ($strength > 2) $chars .= "!@#$%";
    if ($strength > 3) $chars .= '^&*(-_=+)';
    $i = 0;$key = '';
    while ($i <= $length) {$key .= $chars[rand(0, strlen($chars))];$i++;}
    return $key;  
}


echo generatePassword(9);
echo generatePassword(9,1);
echo generatePassword(9,2);
echo generatePassword(9,3);
echo generatePassword(9,4);
echo generatePassword(50,4);


v6qu8my20e
66qv24hero
QswQeNGX1W
@VdQ$7V1kX
l5(11JLmGV
ww$ec6vbc$oh&cr#_w+g&2chQHn1%9TQGXj*ZmT)tHaBH$7(@

Hiç yorum yok: