【发布时间】:2026-01-07 05:15:01
【问题描述】:
我阅读并遵循了关于 password_hash 的 PHP 文档并得到了这个:
<?php
// first determine if a supplied password is valid
$options = ['cost' => 12,];
$hashedPassword = password_hash($plaintextPassword, PASSWORD_DEFAULT, $options);
if (password_verify($plaintextPassword, $hashedPassword)) {
// now determine if the existing hash was created with an algorithm that is
// no longer the default
if (password_needs_rehash($hashedPassword, PASSWORD_DEFAULT)) {
// create a new hash with the new default
$newHashedPassword = password_hash($plaintextPassword, PASSWORD_DEFAULT);
// and then save it to your data store
//$db->update(...);
}
}
?>
我真的很想知道当第一个哈希已经有效时是否有必要再次 hash_password。
【问题讨论】:
-
hash_password是什么?
标签: php hash passwords bcrypt php-password-hash