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.
1 2 3 4 5 6 7 8 9 10 | function randomPassword($length) { $possible = '0123456789!@#$%^&*()_+' . 'abcdefghijklmnopqrstuvwxyz' . 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' . $str = ""; while (strlen($str) < $length) { $str .= substr($possible, (rand() % strlen($possible)), 1); } return($str); } |