PHP Password Generator
Published by philipnorton42 on Sat, 03/08/2008 - 17:15Here is a very simple function that will generate a string of random characters, ideal if you want to create a password for a new user.
1 2 3 4 5 6 7 8 9 | function generatePassword($length=10) { $pass = ''; $parts = array_merge(range(0, 9),range('a', 'z'),range('A', 'Z')); for ($i=0; strlen($pass) <= $length; $i++) { $pass .= $parts[array_rand($parts)]; } return $pass; } |
Use the function like this.
echo generatePassword();
To create a longer password string just pass a parameter with the function.
echo generatePassword(5);Category:
Comments
Example of this in action
Password Generator (not verified) - Thu, 06/02/2011 - 11:46I have generated a very similar Password generator. It works really well and get quite a few hits towards it as well.
Add new comment