Created
September 2, 2013 17:26
-
-
Save raphaelchaib/6415268 to your computer and use it in GitHub Desktop.
PHP: Simple random password generator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function randomPassword($length = 10) { | |
| $alphabet = 'abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789'; | |
| $pass = array(); //remember to declare $pass as an array | |
| $alphaLength = strlen($alphabet) - 1; //put the length -1 in cache | |
| for ($i = 0; $i < $length; $i++) { | |
| $n = rand(0, $alphaLength); | |
| $pass = $alphabet[$n]; | |
| } | |
| return implode($pass); //turn the array into a string | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment