如何在php中生成安全的激活字符串? [英] How to generate a secure activation string in php?
问题描述
用户订阅电子邮件到我的网站后。我的网站会生成电子邮件确认并发送给他们。在电子邮件内容中,我需要包含激活密钥,如:
After user subscribe email to my website. My website will generate an email confirmation and send to them. In the email content, i need to include activation key, something like:
www.domain.com/activate.php?key=$generatedKey
www.domain.com/activate.php?key=$generatedKey
如何生成密钥?使用sha1($ email)??
How do you generate the key? using sha1($email)??
生成密钥后,我将其存储在数据库中,这样当用户点击链接时,我可以用数据库验证它?我是新的,请指教..我需要一个电子邮件确认脚本..
After generate the key, i store it in database, so that when user click the link I can verified it with the database?? I am new to it, please advise.. I need an Email Confirmation script..
推荐答案
个人来说,只是我使用组合例如:
Personally, just I use a combination of things like:
$generatedKey = sha1(mt_rand(10000,99999).time().$email);
碰撞的机会很小,但我建议先检查你的数据库,然后发送出去(使用UNIQUE约束是一种简单的方法)。
The chance of collision is small, but I recommend checking your database first before sending it out (using UNIQUE constraints is an easy way).
这篇关于如何在php中生成安全的激活字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!