Last active
October 2, 2015 11:32
-
-
Save hongster/ebe241e195960c6b73b6 to your computer and use it in GitHub Desktop.
Generate password/key that avoids user mistakes.
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 | |
/** | |
* Generate random password of given length. | |
* | |
* @param int $length | |
* @return string | |
*/ | |
private 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