Skip to content

Instantly share code, notes, and snippets.

@ruliarmando
Last active August 29, 2015 13:56
Show Gist options
  • Save ruliarmando/9064643 to your computer and use it in GitHub Desktop.
Save ruliarmando/9064643 to your computer and use it in GitHub Desktop.
Modified UserIdentity
<?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
{
const ERROR_LIMIT_REACHED = 666;
/**
* 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;
elseif(/* limit user habis */)
$this->errorCode=self::ERROR_LIMIT_REACHED;
else
$this->errorCode=self::ERROR_NONE;
return !$this->errorCode;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment