use*_*174 5 php passwords hash bcrypt phalcon
我在使用 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');
}
Run Code Online (Sandbox Code Playgroud)
在我的注册中,我有:
$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
}
Run Code Online (Sandbox Code Playgroud)
似乎我正在按照文档做所有事情, 但似乎不起作用。任何人都可以请帮助我。