如何生成随机的、唯一的字母数字字符串? [英] How to generate a random, unique, alphanumeric string?

查看:52
本文介绍了如何生成随机的、唯一的字母数字字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用数字和字母生成随机的唯一字符串以用于验证链接?就像您在网站上创建帐户时,它会向您发送一封带有链接的电子邮件,您必须单击该链接才能验证您的帐户

How would it be possible to generate a random, unique string using numbers and letters for use in a verify link? Like when you create an account on a website, and it sends you an email with a link, and you have to click that link in order to verify your account

如何使用 PHP 生成其中之一?

How can I generate one of those using PHP?

推荐答案

安全声明:此解决方案不应用于随机性质量可能影响应用程序安全性的情况.特别是 rand()uniqid() 不是加密安全的随机数发电机.请参阅 Scott 的回答 以获得安全的替代方案.

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))

这篇关于如何生成随机的、唯一的字母数字字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆