Advertisement
Guest User

Untitled

a guest
Jul 6th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.14 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * This class authenticates against the user table and stores a user object in
  5.  * the Zend_Auth identity if successful.
  6.  */
  7. class My_AuthAdapter implements Zend_Auth_Adapter_Interface
  8. {
  9.     private $_username;
  10.     private $_password;
  11.  
  12.     public function setUsername($username)
  13.     {
  14.         $this->_username = $username;
  15.     }
  16.  
  17.     public function setPassword($password)
  18.     {
  19.         $this->_password = $password;
  20.     }
  21.  
  22.     public function authenticate()
  23.     {
  24.         $db = Zend_Registry::get('db');
  25.         $stmt = $db->prepare('
  26.            SELECT password_salt, password_hash FROM user WHERE username = ?
  27.            ');
  28.         $stmt->execute(array($this->_username));
  29.  
  30.         // if we have a user, check the hashed password
  31.         if (($row = $stmt->fetch()) !== false) {
  32.             $hashedPassword = sha1($this->_password . $row['password_salt']);
  33.             if ($hashedPassword == $row['password_hash']) {
  34.                 return new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $this->_username);
  35.             }
  36.         }
  37.         return new Zend_Auth_Result(Zend_Auth_Result::FAILURE, null);
  38.     }
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement