Skip to content

Instantly share code, notes, and snippets.

@mbischof
Last active October 11, 2015 21:48
Show Gist options
  • Save mbischof/3924066 to your computer and use it in GitHub Desktop.
Save mbischof/3924066 to your computer and use it in GitHub Desktop.
Yii DB UserIdentity
<?php
class UserIdentity extends CUserIdentity
{
private $_id;
public function authenticate()
{
$username = strtolower($this->username);
$user = User::model()->find('LOWER(username) = ?', array($username));
if ($user === null) {
$this->errorCode = self::ERROR_USERNAME_INVALID;
} elseif (md5($this->password) !== $user->password) {
$this->errorCode = self::ERROR_PASSWORD_INVALID;
} else {
$this->_id = $user->id;
$this->username = $user->username;
$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