UserIdentity::authenticate PHP Method

authenticate() public method

The example implementation makes sure if the username and password are both 'demo'. In practical applications, this should be changed to authenticate against some persistent user identity storage (e.g. database).
public authenticate ( ) : boolean
return boolean whether authentication succeeds.
    public function authenticate()
    {
        $users = array('demo' => 'demo', 'admin' => 'admin');
        if (!isset($users[$this->username])) {
            $this->errorCode = self::ERROR_USERNAME_INVALID;
        } elseif ($users[$this->username] !== $this->password) {
            $this->errorCode = self::ERROR_PASSWORD_INVALID;
        } else {
            $this->errorCode = self::ERROR_NONE;
        }
        return !$this->errorCode;
    }

Usage Example

 /**
  * Logs in the user using the given username and password in the model.
  * @return boolean whether login is successful
  */
 public function login()
 {
     if ($this->_identity === null) {
         $this->_identity = new UserIdentity($this->email, $this->password);
         $this->_identity->authenticate();
     }
     return $this->_identity->login();
 }
All Usage Examples Of UserIdentity::authenticate
UserIdentity