函数名:sodium_crypto_pwhash_str_needs_rehash()
适用版本:PHP 7.2.0及以上版本
函数说明:该函数用于检查以前使用sodium_crypto_pwhash_str()函数生成的密码散列是否需要重新计算。
语法:bool sodium_crypto_pwhash_str_needs_rehash(string $hash, int $opslimit, int $memlimit)
参数:
返回值:如果密码散列需要重新计算,则返回true;否则返回false。
示例:
$hash = '$argon2id$v=19$m=65536,t=4,p=1$S3JvbE5vZGUgU3RyaW5n$Y4plnXZMnK0Bq2w9WJy9jD0I9Hb1W2w+GKw0q6tZv0s';
// 假设当前的迭代次数和内存限制
$currentOpsLimit = 4;
$currentMemLimit = 65536;
if (sodium_crypto_pwhash_str_needs_rehash($hash, $currentOpsLimit, $currentMemLimit)) {
// 密码散列需要重新计算
echo "密码散列需要重新计算";
} else {
// 密码散列无需重新计算
echo "密码散列无需重新计算";
}
注意事项: