Last active
July 24, 2018 19:59
-
-
Save lasekmiroslaw/4893f257b4b229323a9bab431cef342a to your computer and use it in GitHub Desktop.
Random token generator
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
class TokenGenerator | |
{ | |
private const ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; | |
public function getRandomSecureToken(int $length): string | |
{ | |
$maxNumber = strlen(self::ALPHABET); | |
$token = ''; | |
for ($i = 0; $i < $length; $i++) { | |
$token .= self::ALPHABET[random_int(0, $maxNumber - 1)]; | |
} | |
return $token; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment