Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * This class authenticates against the user table and stores a user object in
- * the Zend_Auth identity if successful.
- */
- class My_AuthAdapter implements Zend_Auth_Adapter_Interface
- {
- private $_username;
- private $_password;
- public function setUsername($username)
- {
- $this->_username = $username;
- }
- public function setPassword($password)
- {
- $this->_password = $password;
- }
- public function authenticate()
- {
- $db = Zend_Registry::get('db');
- $stmt = $db->prepare('
- SELECT password_salt, password_hash FROM user WHERE username = ?
- ');
- $stmt->execute(array($this->_username));
- // if we have a user, check the hashed password
- if (($row = $stmt->fetch()) !== false) {
- $hashedPassword = sha1($this->_password . $row['password_salt']);
- if ($hashedPassword == $row['password_hash']) {
- return new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $this->_username);
- }
- }
- return new Zend_Auth_Result(Zend_Auth_Result::FAILURE, null);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement