牛牛在线工具

sodium_crypto_pwhash_str_verify()

收录 8868 个 PHP 函数,含用途说明与用法示例。

sodium_crypto_pwhash_str_verify()

验证密码哈希字符串的正确性

函数名称:sodium_crypto_pwhash_str_verify() 适用版本:PHP 7.2.0以上 函数说明:sodium_crypto_pwhash_str_verify() 函数用于验证密码哈希字符串的正确性。它将验证密码是否与哈希字符串匹配。 语法:sodium_crypto_pwhash_str_verify(string $hash, string $password): bool 参数: $hash:密码的哈希字符串,通常是在使用 sodium_crypto_pwhash_str() 函数生成的。 $password:要验证的密码。 返回值: 如果密码与哈希字符串匹配,则返回 true,否则返回 false。 示例: // 生成密码哈希字符串 $hash = sodium_crypto_pwhash_str('password', SODIUM_CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE, SODIUM_CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE); // 验证密码哈希字符串的正确性 if (sodium_crypto_pwhash_str_verify($hash, 'password')) { echo "密码匹配"; } else { echo "密码不匹配"; } 在上面的示例中,我们首先使用 sodium_crypto_pwhash_str() 函数生成密码的哈希字符串。然后,我们使用 sodium_crypto_pwhash_str_verify() 函数来验证密码哈希字符串的正确性。如果密码与哈希字符串匹配,则输出 "密码匹配";否则输出 "密码不匹配"。请注意,这只是一个简单的示例,实际使用时,应该根据具体需求进行适当的错误处理和安全措施。