mint

UserIdentity.php

Jun 23rd, 2012
78
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. /**
  4.  * UserIdentity represents the data needed to identity a user.
  5.  * It contains the authentication method that checks if the provided
  6.  * data can identity the user.
  7.  */
  8. class UserIdentity extends CUserIdentity
  9. {
  10. private $_id;
  11. /**
  12. * Authenticates a user using the User data model.
  13. * @return boolean whether authentication succeeds.
  14. */
  15. public function authenticate()
  16. {
  17.     $user=User::model()->findByAttributes(array('username'=>$this->username));
  18.          $pass1=$user->password;
  19.          $pass2=$this->password;
  20.          $n=strlen($pass1);
  21.          
  22.     if($user===null)
  23.     {
  24.         $this->errorCode=self::ERROR_USERNAME_INVALID;
  25.     }
  26.     else
  27.     {
  28.        
  29.         if(strncmp($pass1,$pass2,$n)!==0)
  30.         {
  31.  
  32.                 $this->errorCode=self::ERROR_PASSWORD_INVALID;
  33.         }
  34.         else
  35.         {   Yii::log('length: '.$n,'trace');
  36.             $this->_id = $user->id;
  37.             Yii::log('id: '.$this->_id,'trace');
  38.             $this->errorCode == self::ERROR_NONE;
  39.                         Yii::log('errorCode: '.$this->errorCode,'trace');
  40.         }
  41.     }
  42.               Yii::log('errorCode: '.$this->errorCode,'trace');
  43.     return !$this->errorCode;
  44.  
  45. }
  46.  
  47. public function getId()
  48. {
  49.     return $this->_id;
  50. }
  51. }
RAW Paste Data