Created
August 23, 2014 10:02
-
-
Save xpertspk/74316c33bc9d5670f3bb to your computer and use it in GitHub Desktop.
PHP: generatePassword function
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
function generatePassword ($length = 10) | |
{ | |
$password = ""; | |
$possible = "0123456789bcdfghjkmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ"; | |
$i = 0; | |
while ($i < $length) { | |
$char = substr($possible, mt_rand(0, strlen($possible)-1), 1); | |
if (!strstr($password, $char)) { | |
$password .= $char; | |
$i++; | |
} | |
} | |
return $password; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment