Last active
August 29, 2015 14:10
-
-
Save lcherone/6b0e04d6bc6eb8306f20 to your computer and use it in GitHub Desktop.
Random A1phaNumEr1c infinite length string function
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 | |
echo passgen(20); //K4YFnMW5muf0kZTMl6h3 | |
function passgen($length = 20) | |
{ | |
// define base string - add multiplex to pad to an infinate length | |
$alpha = str_repeat( | |
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", | |
intval($length + 1) | |
); | |
$numeric = str_repeat( | |
"0123456789", | |
intval($length + 1) | |
); | |
//shuffle the base string and set first character as an alpha | |
return substr(str_shuffle($alpha), 0, 1) | |
. substr(str_shuffle($alpha.$numeric), 0, intval($length - 1)); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Added multiplex onto numbers to increase the number entropy in resulting hash