"php: how to generate a random, unique, alphanumeric string for use in a secret link?" Code Answer

4

Security Notice: This solution should not be used in situations where the quality of your randomness can affect the security of an application. In particular, rand() and uniqid() are not cryptographically secure random number generators. See Scott's answer for a secure alternative.

If you do not need it to be absolutely unique over time:

md5(uniqid(rand(), true))

Otherwise (given you have already determined a unique login for your user):

md5(uniqid($your_user_login, true))
By Evernoob on December 27 2022

Answers related to “php: how to generate a random, unique, alphanumeric string for use in a secret link?”

Only authorized users can answer the search term. Please sign in first, or register a free account.