Advertisement
Guest User

Untitled

a guest
Jun 21st, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.13 KB | None | 0 0
  1. class ZC_Auth_Adapter
  2.     implements Zend_Auth_Adapter_Interface
  3. {
  4.     const NOT_FOUND_MSG = "Account not found";
  5.     const BAD_PW_MSG    = "Password is invalid";
  6.  
  7.     protected $user;
  8.  
  9.     protected $username = "";
  10.     protected $password = "";
  11.  
  12.     public function  __construct($username, $password)
  13.     {
  14.         $this->username = $username;
  15.         $this->password = $password;
  16.     }
  17.  
  18.     public function authenticate()
  19.     {
  20.         try
  21.         {
  22.             $this->user = Model_User::authenticate($this->username, $this->password);
  23.             return $this->createResult(Zend_Auth_Result::SUCCESS);
  24.         } catch (Exception $e) {
  25.             if($e->getMessage() == Model_User::WRONG_PASSWORD)
  26.                     return $this->createResult(Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID, array(self::BAD_PW_MSG));
  27.  
  28.             if($e->getMessage() == Model_User::NOT_FOUND)
  29.                     return $this->createResult(Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND, array(self::NOT_FOUND_MSG));
  30.         }
  31.     }
  32.  
  33.     private function createResult($code, $messages = array())
  34.     {
  35.         return new Zend_Auth_Result($code, $this->user, $messages);
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement