Skip to content

Instantly share code, notes, and snippets.

@thomwiggers
Created February 7, 2016 21:05
Show Gist options
  • Save thomwiggers/76bb23bfdd061d956747 to your computer and use it in GitHub Desktop.
Save thomwiggers/76bb23bfdd061d956747 to your computer and use it in GitHub Desktop.
/**
* 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