创建一个由参数为email
和hash
组成的查询字符串的验证链接,您认为如何?
- email是注册用户的html编码的纯字符串email,
- 哈希是PHP函数
password_hash
的结果值,其中第一个参数的字符串是从数据库中选择的具有固定盐字符串的唯一id用户号。
我还在考虑切换盐,但是可以猜测给定电子邮件的id用户号,将其传递给password_hash
并获得查询字符串的有效哈希(即使password_hash自动添加自己的盐),所以我认为这是不安全的。
我是这样想的:
// the result of SELECT from the database (I use Mysql)
$id = '5';
// fixed salt string
$salt = 'xbrENiBq6kb87WrZYhxS';
$email = urlencode($email);
$key = $id . $salt;
$hash = urlencode(password_hash($key, PASSWORD_DEFAULT));
// the resulted querystring:
$url = "somesite.com/index.php?email=$email&hash=$hash";
然后我将它发送到用户邮箱
请告诉我,你是怎么想的?很多谢谢!
根据您的编码,您可以尝试混合各种类型的编码以达到实际值。与数据库进行比较的最终结果必须是md5
字符串,这样也不会损失性能。
SELECT md5(your_field) FROM table
对不起,我的英语不好。