Created
July 30, 2013 14:14
-
-
Save olimortimer/6113271 to your computer and use it in GitHub Desktop.
PHP: Random Password
This file contains 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 = 8) { | |
$password = false; | |
$characters = 'abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789'; | |
$charsLength = strlen($characters) - 1; | |
for ($i = 0; $i < $length; $i++) { | |
$n = rand(0, $charsLength); | |
$password .= $characters[$n]; | |
} | |
return $password; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment