Php Zend\Authentication是否提供了检查身份是否存在的方法?

Php Zend\Authentication是否提供了检查身份是否存在的方法?,php,authentication,zend-framework2,Php,Authentication,Zend Framework2,使用Zend\Authentication对DB进行身份验证非常简单: $isAuthenticated = $this->getAuthService($db)->getAdapter() ->setIdentity($this->request->getPost('username')) ->setCredential($this->request->getPost('password')) ->authentic

使用Zend\Authentication对DB进行身份验证非常简单:

$isAuthenticated = $this->getAuthService($db)->getAdapter()
    ->setIdentity($this->request->getPost('username'))
    ->setCredential($this->request->getPost('password'))
    ->authenticate()
    ->isValid()
    ;
但如果身份验证成功,则只返回一个布尔值。Zend\Authentication是否提供了一种检查数据库中是否存在身份并返回此信息的方法?我可以先做一个sql查询,看看它是否在数据库中,但在我做之前,我想确定这个类没有提供一个内置的解决方案


这样,我可能会收到一条“密码不正确,请重试”消息,而不是“用户帐户不存在”。或者我可以说,不显示此信息是一种安全功能,不麻烦:P

是的,您有代码。您可以这样使用:

// inside of AuthController / loginAction
$result = $this->auth->authenticate($adapter);

switch ($result->getCode()) {

case Result::FAILURE_IDENTITY_NOT_FOUND:
    /** do stuff for nonexistent identity **/
    break;

case Result::FAILURE_CREDENTIAL_INVALID:
    /** do stuff for invalid credential **/
    break;

case Result::SUCCESS:
    /** do stuff for successful authentication **/
    break;

default:
    /** do stuff for other failure **/
    break;
}

检查AuthenticationOn文档

不要发出不同的错误消息。只要说“它起作用了”和“它没起作用”。您不希望任何人能够检查特定的用户帐户是否存在。那是件坏事。