【发布时间】:2014-07-17 01:57:13
【问题描述】:
我使用此语句通过 Phalcon 对密码进行哈希处理:
$hashedPassword= $this->security->hash($password)
但是这个语句使用相同的密码返回不同的结果。
示例:
设置 $password=123
我得到具有以下值的 $hashedPassword:
$2a$08$T2Rf9IcQHTj7TpY.gsfGiexZ35/KK9kS3fLElxaw8LGXhjnE01f5K 和 $2a$08$E2mjApECMbRKQFZodgLkEOpDLSV/tEjTe1HV3q2LLG9UINj9M9GBm 和 $2a$08$aZmgsMmG2xRueVzP6tkx2ucWGPZMzUwIccXbLJnqoRwDsSnT4zc.q
这是我用来检查用户密码的代码,
请让我知道我错过了什么。
if ($this->request->isPost() == true)
{
$email = $this->request->getPost ("email");
$password = $this->request->getPost ("password");
$conditions = "email = ?1 AND admin = ?2";
$parameters = array(1 => $email, 2 => 1);
$users = Users::findFirst(array(
$conditions,
"bind" => $parameters
));
if($users)
{
$security = new Phalcon\Security();
$checkHashValue = $security->checkHash($password, $user->password);
if($checkHashValue)
{
$this->flash->success($users->fullname);
}
else
{
//Print debug information
$hash = $security->hash($password);
$checkHash = $security->checkHash($password, $hash);
$this->flash->error("Password: ". $password.
"<br/>Hash: " . $hash . "<br/>Check Hash: " . $checkHash .
"<br/>Check HashValue: ". $checkHashValue);
}
}
else
{
$this->flash->error($password);
}
}
解决方案:我的变量“user”而不是“users”中有错字。
【问题讨论】: