2015-06-14 105 views
-1

我正在使用password_hash()函数。如何验证哈希密码

现在它可以散列密码,但我该如何验证它?

+5

http://php.net/manual/en/function.password-verify.php – dnuka

+0

谁upvoting此创建一个哈希?小心解释为什么? –

回答

3

那么这个选项的功能被称为:password_verify

它如何工作是这样的;

<?php 
$password = "[PASS]"; //Password user fill in. 
$hash= "[HASH]"; //The hashed password that you saved. 
$checkPass = password_verify($password, $hash); //This returns a boolean; true or false 
if ($checkPass == true) 
{ 
    echo 'Password is good!'; 
} 
else 
{ 
    echo 'Password is wrong!'; 
} 
?> 
+2

哇,快速响应thx!这效果很好! – LenapCapo

1
boolean password_verify (string $password , string $hash) 

验证给定的哈希给定的密码相匹配。

请注意,password_hash()返回算法,成本和salt作为返回散列的一部分。因此,所有需要验证散列的信息都包含在其中。这允许验证功能验证散列,而不需要为盐或算法信息单独存储。

密码 用户的密码。

哈希 通过password_hash()

http://php.net/manual/en/function.password-verify.php