Skip to content

Instantly share code, notes, and snippets.

@jamband
Last active September 28, 2015 10:38
Show Gist options
  • Save jamband/1426228 to your computer and use it in GitHub Desktop.
Save jamband/1426228 to your computer and use it in GitHub Desktop.
<?php
class UserIdentity extends CUserIdentity
{
private $id;
public function authenticate()
{
$model = User::model()->findByAttributes(array(
'username' => $this->username,
));
$ph = new PasswordHash(
Yii::app()->params['iteration_count_log2'],
Yii::app()->params['portable_hashes']
);
if (!$model) {
$this->errorCode = self::ERROR_USERNAME_INVALID;
} else if (!$ph->CheckPassword($this->password, $model->password)) {
$this->errorCode = self::ERROR_PASSWORD_INVALID;
} else {
$this->id = $model->id;
$this->errorCode = self::ERROR_NONE;
}
return !$this->errorCode;
}
public function getId()
{
return $this->id;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment