How to create a random password in PHP
I am trying to generate a random password in PHP.
If you ever have the need to create a random password or username you can use something like this.
function randomPassword($length) {
$possible = '0123456789!@#$%^&*()_+' .
'abcdefghijklmnopqrstuvwxyz' .
'ABCDEFGHIJKLMNOPQRSTUVWXYZ' .
$str = "";
while (strlen($str) < $length) {
$str .= substr($possible, (rand() % strlen($possible)), 1);
}
return($str);
}
