我讀了關於crypt()
函數的php.net手冊。這裏是我的代碼:PHP crypt()錯誤
#code.....
#we retrieve existing salt and password from database
$salt=$saltquery['salt'];
#$ex_password - existing password
$ex_password=$saltquery['pass'];
#$pass defined earlier. that's input
$password_hash=crypt($pass, '$2a$07$'.$salt.'');
if (crypt($password_hash, $ex_password)==$ex_password) {
#everything is ok
} else {
#username/password combination doesn't exists
$msgText = "Oops! Check your username and password";
$pass=NULL;
}
我仍然收到錯誤'哎呀!檢查你的用戶名和密碼'。我檢查數據庫和從$password_hash
輸出,他們匹配。 也許是更好的像這樣的代碼:
#.....
if ($password_hash==$ex_password){}
#.....
我很抱歉這麼奇怪的缺陷 – treng 2012-08-03 17:41:13
所以我不需要在數據庫中存儲鹽? – treng 2012-08-03 17:51:16
不分開。它已經存儲爲密碼摘要的一部分(美元符號之間的最後一部分) – knittl 2012-08-03 17:53:09