UserIdentity.php 929 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. /**
  3. * UserIdentity represents the data needed to identity a user.
  4. * It contains the authentication method that checks if the provided
  5. * data can identity the user.
  6. */
  7. class UserIdentity extends CUserIdentity
  8. {
  9. /**
  10. * Authenticates a user.
  11. * The example implementation makes sure if the username and password
  12. * are both 'demo'.
  13. * In practical applications, this should be changed to authenticate
  14. * against some persistent user identity storage (e.g. database).
  15. * @return boolean whether authentication succeeds.
  16. */
  17. public function authenticate()
  18. {
  19. $users=array(
  20. // username => password
  21. 'demo'=>'demo',
  22. 'admin'=>'admin',
  23. );
  24. if(!isset($users[$this->username]))
  25. $this->errorCode=self::ERROR_USERNAME_INVALID;
  26. elseif($users[$this->username]!==$this->password)
  27. $this->errorCode=self::ERROR_PASSWORD_INVALID;
  28. else
  29. $this->errorCode=self::ERROR_NONE;
  30. return !$this->errorCode;
  31. }
  32. }