我在使用Phalcon PHP检查bcrypted密码时遇到了一些问题。我有以下代码:
登录脚本中,我会检查密码:
$username = $this->request->getPost('username', 'string');
$password = $this->request->getPost('password', 'string');
$conditions = "Username = :username:";
$parameters = array (
"username" => $username
);
$user = Users::findFirst(array($conditions, 'bind' => $parameters));
//check if user exists
if (count($user) > 0 && $user !== false) {
if ($this->security->checkHash($password, $user->Password)) //always fails {
//login
$this->session->set('username', $user->Password);
$this->response->redirect('index');
}
在我的注册表单中,我有以下内容:
$name = $this->request->getPost('name', 'string');
$lastName = $this->request->getPost('lastName', 'string');
$username = $this->request->getPost('username', 'string');
$password = $this->request->getPost('password', 'string');
$email = $this->request->getPost('email', 'email');
$user = new Users(); //model
$user->Name = $name;
$user->LastName = $lastName;
$user->Username = $username;
$user->Password = $this->security->hash($password);
$user->Email = $email;
if ($user->save() == true) {
//registered
} else {
//error
}
看起来我按照 文档 做了一切,但好像不起作用。请问有人能帮帮我吗。
$user->Password
中接收到的密码和$this->security->hash($password);
产生的哈希值是否匹配?它们是否相同? - Ian Bytchek$this->session->set('username', $user->Password);
- Ian Bytchek