Does Zend\Authentication offer a way to check if an identity exists?

Its simple enough to use Zend\Authentication to authenticate against a DB:

$isAuthenticated = $this->getAuthService($db)->getAdapter()
    ->setIdentity($this->request->getPost('username'))
    ->setCredential($this->request->getPost('password'))
    ->authenticate()
    ->isValid()
    ;

But this just returns a Boolean value if authentication was successful. Does Zend\Authentication offer a way to check if the identity is present in a DB and return this info as well? I could just do an sql query first to see if its in the DB, but before I do that I wanted to be sure there wasn't an in box solution the class offered for this.

This way I could have an "Incorrect password please try again" message vs "User account does not exist" . Or I could just say that not displaying this info is a security feature and not bother :P

Answers


Yes, you have the code. And you can use as this:

// 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;
}

Check the Authenticacion document http://framework.zend.com/manual/2.3/en/modules/zend.authentication.intro.html


Need Your Help

Check All checkbox function inside a modal

javascript html angularjs checkbox modal-dialog

If user clicks 'add data' a modal opens, I have individual checkboxes for data1,data2,data3,data4. I also have a check all checkbox. If user clicks this, it should be able to select all above 4, if

persistence.xml not working

jpa persistence.xml

I have a problem with running a web project with JPA. Netbeans shows the message: