Created
April 27, 2017 18:55
-
-
Save barbietunnie/416aeed5482a2684019820b1d2aed96b to your computer and use it in GitHub Desktop.
Creating unique tokens in PHP
This file contains hidden or 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 | |
| // bin2hex(random_bytes($length)) | |
| $token = bin2hex(random_bytes(64)); | |
| /* | |
| Examples: | |
| 39e9289a5b8328ecc4286da11076748716c41ec7fb94839a689f7dac5cdf5ba8bdc9a9acdc95b95245f80a00d58c9575c203ceb541507cce40dd5a96e9399f4a | |
| 1c46538c712e9b5bf0fe43d692147004f617b494d004e29daaf33e4528f253db5d911a690856f0b77cfa98103c8231bffff869f179125d17d28e52bfadb9f205 | |
| ... | |
| */ | |
| // If you aren't using PHP7 or above, you can fall back to | |
| $token = bin2hex(openssl_random_pseudo_bytes(64)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment