具有相同值的不同 MD5 散列

Different MD5 hash with the same value

我正在做一个注册页面,我用md5加密用户的密码,当我做登录页面时每次尝试登录时都说密码错误,所以我检查了md5哈希是否与在数据库中,但它不是,而且我确定密码是正确的。我在登录页面和注册页面也使用相同的代码:$password = md5($password)

你把它变得比必要的更复杂了。参见:password_hash and password_verify.

Note: Caution It is strongly recommended that you do not generate your own salt for this function. It will create a secure salt automatically for you if you do not specify one.

参见:Hashing Passwords with the PHP

创建密码哈希:

$hash = password_hash($password, PASSWORD_DEFAULT);

确保将散列存储在容量超过 60 个字符的列中。

验证密码:

if (password_verify($password, $hash)) {
    // Success!
}
else {
    // Invalid credentials
}