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