<?php
/**
* UserIdentity represents the data needed to identity a user.
* It contains the authentication method that checks if the provided
* data can identity the user.
* 用户身份代表身份用户所需要的数据
* 它包含身份验证方法做了检查,如果所提供的、数据可以标识用户
*/
class UserIdentity extends CUserIdentity
{
/**
* Authenticates a user.
* The example implementation makes sure if the username and password
* are both 'demo'.
* In practical applications, this should be changed to authenticate
* against some persistent user identity storage (e.g. database).
* @return boolean whether authentication succeeds.
* 用户进行身份验证。
* 例如实现确保,如果用户名和密码
* 都是“演示”。
* 在实际应用中,这将改变进行身份验证
* 对某些持久性的用户身份存储(如数据库)。
* @返回布尔值是否验证成功。
*/
public function authenticate()
{
$users=array(
// username => password
'demo'=>'demo',
'admin'=>'admin',
'xlc'=>'xlc'
);
if(!isset($users[$this->username]))
$this->errorCode=self::ERROR_USERNAME_INVALID;
elseif($users[$this->username]!==$this->password)
$this->errorCode=self::ERROR_PASSWORD_INVALID;
else
$this->errorCode=self::ERROR_NONE;
return !$this->errorCode;
}
}