我阅读了关于crypt()
功能的 php.net 手册。这是我的代码:
#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){}
#.....