首页 > 解决方案 > PHP如何从相同的字符串创建相同的哈希?

问题描述

还没有找到确切的答案。我想获取浏览器指纹,然后从指纹创建哈希并记录在 mysql 中。因此,当用户下次登录时,我将 mysql 哈希与特定登录的哈希进行比较,如果哈希不同,则决定向用户发送电子邮件。

问题是如何从相同的字符串创建相同的哈希?

试过了md5

$string = 'I could use a users IP address as the fingerprint, however, there could be multiple other users on the same IP. This is how passwords are typically stored (using this or another hash function, typically with a salt method added.) Checking a password is then done by hashing the input and comparing to the stored hash.';

echo md5($string).  "\n";
echo md5($string).  "\n";
echo md5($string).  "\n";

示例在这里http://sandbox.onlinephpfunctions.com/code/8bd6dfc7a1ba69edb6e175c9a2c04d9a3704228b

正如我所见,所有哈希值都是相同的(在 2 个不同的浏览器上尝试过,所以时间也不同,哈希值相同)。那么我可以 100% 确定md5从相同的字符串创建相同的哈希吗?

标签: phphashmd5

解决方案


推荐阅读