Last active
October 2, 2015 11:33
-
-
Save hongster/789d735d19cb3ed03ae5 to your computer and use it in GitHub Desktop.
Avoid using characters like (0,o,O,1,i,l) in generating random passwords.
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 = 6) { | |
// Non-ambiguous chars | |
$alphabet = 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789'; | |
$alphamax = strlen($alphabet) - 1; | |
$password = ''; | |
for ($i = 0; $i < $length; $i++) { | |
$password .= $alphabet[mt_rand(0, $alphamax)]; | |
} | |
return $password; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment