Created
February 7, 2016 21:05
-
-
Save thomwiggers/76bb23bfdd061d956747 to your computer and use it in GitHub Desktop.
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
/** | |
* Generate a random string in [a-z0-9] | |
* | |
* @param Length | |
* @return random alphanumeric string | |
*/ | |
public static function make_secret($Length = 32) { | |
$Str = ''; | |
while (strlen($Str) < $Length) { | |
$Hex = bin2hex(mcrypt_create_iv(10, MCRYPT_DEV_URANDOM)); | |
$Ascii = base_convert($Hex, 16, 36); | |
$Str .= str_pad($Ascii, 16, '0', STR_PAD_LEFT); | |
} | |
return substr($Str, 0, $Length); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment