2015-06-14 107 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