How to generate a random password in PHP 😁
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
function randomPassword($length = 8, $seed = '') { $password = ""; $possible = "0123456789"; $i = 0; mt_srand(($seed == '') ? rand() : $seed); while ($i < $length) { $char = substr($possible, mt_rand(0, strlen($possible) - 1), 1); if (!strstr($password, $char)) { $password .= $char; $i++; } } return $password; } |