Php Yii:强制认证
是否存在强制Php Yii:强制认证,php,yii,Php,Yii,是否存在强制yii在不查阅数据库的情况下通过给定用户名对用户进行身份验证的方法 我的应用程序将使用api登录,在未编写api之前,我们无法使用app 由于此api我们没有用户模型,因此,当尝试使用user::model() 下面的代码显示了yiic生成的默认UserIdentity.php。它根据需要使用硬编码用户和密码 <?php /** * UserIdentity represents the data needed to identity a user. * It conta
yii
在不查阅数据库的情况下通过给定用户名对用户进行身份验证的方法
我的应用程序将使用api
登录,在未编写api
之前,我们无法使用app
由于此api
我们没有用户
模型,因此,当尝试使用user::model()
下面的代码显示了yiic生成的默认
UserIdentity.php
。它根据需要使用硬编码用户和密码
<?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',
);
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;
}
}
<?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',
);
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;
}
}