因此,我已经在我的 di 中设置了安全组件......
--services.php--
$di->set('security', function(){
$security = new Phalcon\Security();
//Set the password hashing factor to 11 rounds
$security->setWorkFactor(11);
return $security;
}, true);
--Custom Auth Library (auth.php)--
$user = Users::findFirstByEmail($login);
if ($user) {
if ($this->security->checkHash($password, $user->password)) {
return true;
}
}
return false;
但是,由于某种原因,这总是返回 false...所以,为了调试,我尝试使用 PHP 的 password_verify 函数,下面的代码直接在我看来:
//Returns false
var_dump($this->security->checkHash('password', '$2a$12$aSa7zLEd24zjh2aoUasxd.hbxIm8IQ0/vMf/8p4LTYI3VtZMJ62Pe'));
//Returns True
var_dump(password_verify('password', '$2a$12$aSa7zLEd24zjh2aoUasxd.hbxIm8IQ0/vMf/8p4LTYI3VtZMJ62Pe'));
我错过了什么???
最佳答案
好吧,看来如果我将散列值和密码都设置为一个变量,它会正确地解析这两个语句。
我感谢所有的帮助,但这是最终的解决方案。
$password = $pass;
$hash = '$2a$12$lDL2eQ1GLJsJhKgPvU6agOnHpwNSBYPtWHF/O/aTvyISzI.ugjyLC';
var_dump($this->security->checkHash($password, $hash));
var_dump(password_verify($password, $hash));
关于php - Phalcon PHP 密码 Bcrypt,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21467350/