我读了关于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