How To Generate a Random Password in PHP
August 30, 2010
Here’s a quick little snippet to generate a random password in php:
function createRandomPassword($length = 7) {
$chars = "ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz23456789!@#$%^&*(){}[]";
$pass = '' ;
while(strlen($pass) <= $length)
{
$pass .= $chars[mt_rand(0, strlen($chars))];
}
return $pass;
}