CUserIdentity.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * CUserIdentity class file
  4. *
  5. * @author Qiang Xue <qiang.xue@gmail.com>
  6. * @link http://www.yiiframework.com/
  7. * @copyright 2008-2013 Yii Software LLC
  8. * @license http://www.yiiframework.com/license/
  9. */
  10. /**
  11. * CUserIdentity is a base class for representing identities that are authenticated based on a username and a password.
  12. *
  13. * Derived classes should implement {@link authenticate} with the actual
  14. * authentication scheme (e.g. checking username and password against a DB table).
  15. *
  16. * By default, CUserIdentity assumes the {@link username} is a unique identifier
  17. * and thus use it as the {@link id ID} of the identity.
  18. *
  19. * @property string $id The unique identifier for the identity.
  20. * @property string $name The display name for the identity.
  21. *
  22. * @author Qiang Xue <qiang.xue@gmail.com>
  23. * @package system.web.auth
  24. * @since 1.0
  25. */
  26. class CUserIdentity extends CBaseUserIdentity
  27. {
  28. /**
  29. * @var string username
  30. */
  31. public $username;
  32. /**
  33. * @var string password
  34. */
  35. public $password;
  36. /**
  37. * Constructor.
  38. * @param string $username username
  39. * @param string $password password
  40. */
  41. public function __construct($username,$password)
  42. {
  43. $this->username=$username;
  44. $this->password=$password;
  45. }
  46. /**
  47. * Authenticates a user based on {@link username} and {@link password}.
  48. * Derived classes should override this method, or an exception will be thrown.
  49. * This method is required by {@link IUserIdentity}.
  50. * @return boolean whether authentication succeeds.
  51. */
  52. public function authenticate()
  53. {
  54. throw new CException(Yii::t('yii','{class}::authenticate() must be implemented.',array('{class}'=>get_class($this))));
  55. }
  56. /**
  57. * Returns the unique identifier for the identity.
  58. * The default implementation simply returns {@link username}.
  59. * This method is required by {@link IUserIdentity}.
  60. * @return string the unique identifier for the identity.
  61. */
  62. public function getId()
  63. {
  64. return $this->username;
  65. }
  66. /**
  67. * Returns the display name for the identity.
  68. * The default implementation simply returns {@link username}.
  69. * This method is required by {@link IUserIdentity}.
  70. * @return string the display name for the identity.
  71. */
  72. public function getName()
  73. {
  74. return $this->username;
  75. }
  76. }