我在我的應用程序中實現了ZfcUser。問題是即使密碼正確,驗證也會失敗。ZfzUser身份驗證始終失敗
我已經深入瞭解了這個問題。我注意到的是,應用程序從密碼中檢索密碼哈希並將其傳遞給Bcrypt驗證方法。
下面是Zend的
代碼if (!$bcrypt->verify($credential, $userObject->getPassword())) {
// Password does not match
$e->setCode(AuthenticationResult::FAILURE_CREDENTIAL_INVALID)
->setMessages(array('Supplied credential is invalid.'));
$this->setSatisfied(false);
return false;
}
現在bcrypt驗證方法的工作原理如下。
public function verify($password, $hash)
{
$result = crypt($password, $hash);
return Utils::compareStrings($hash, $result);
}
我的密碼是'admin123'
,在數據庫中保存它生成的散列"$2y$14$9QsDD3.T3xwCnZsMsiBft.fwLewL.0L5pyViAJY0EbNz0ECIGDi5u"
,但我看到它永遠不會匹配,因爲驗證方法使用的哈希值鹽。我做錯了什麼,或者框架中有一些錯誤/?
在我的用戶實體用於設置密碼的代碼是
public function setPassword($password)
{
$bcrypt = new Bcrypt();
$bcrypt->setCost(14);
$this->password = $bcrypt->create($password);
}
可能的[Zend \ Crypt \ Password \ BCrypt驗證方法]重複(http://stackoverflow.com/questions/32717509/zend-crypt-password-bcrypt-verify-method) – Wilt