我有一个登录应用程序的处理文件。我不明白password_needs_rehash()
的目的,或者它没有起作用。登录已经通过认证并将我传递到正确的页面。但是,我甚至不能使代码回显新哈希。
我是否做得正确?
if
语句没有抛出新哈希,是因为密码不需要重新哈希吗?如果是这样,那么如果密码在DB中被正确地哈希和存储,什么时候需要重新哈希呢?
我的处理文件如下:
$hash = $row['hash'];
$userPassword = $_POST["li_password"];
if (password_verify($userPassword, $hash)) {
if ( password_needs_rehash($hash, PASSWORD_DEFAULT, ['cost' => 12]) ) {
$newhash = password_hash($userPassword, PASSWORD_DEFAULT, ['cost' => 12]);
echo $newhash;
}
} else {
header('Location: http://' . $_SERVER['HTTP_HOST'] . '?error=loginfailed');
exit();
}
PASSWORD_DEFAULT
的值发生了变化,@Xorifelse也会受到影响。 - TRiG