I need an approach to generate a cryptographically secure and unique token in order to use in an online ticket sale service. What issues should I consider to implement and what is the best practice in Php (Laravel)?
Unique token? install paragonie/constant_time_encoding
Base64UrlSafe::encode(random_bytes(9))
This means you have a 50% chance of only two duplicate random values after about 69 billion records (a far cry beyond your 4 billion storage capacity). This means that you will almost never have a collision. You should still make sure every selector you generate is unique before inserting a new one, of course.
source
Note: this is just to answer the question, scroll down for more approach.
Try this:
bin2hex(random_bytes(64));
PHP
bin2hex function : https://www.php.net/manual/en/function.bin2hex.php
PHP
random bytes function : https://www.php.net/manual/en/function.random-bytes.php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With