Last active
October 11, 2015 21:48
-
-
Save mbischof/3924066 to your computer and use it in GitHub Desktop.
Yii DB UserIdentity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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