yii では、ログイン機能を作成しています。ユーザーが正しいユーザー名を入力してもパスワードが間違っている場合、この正しいユーザー名をデータベースで検索し、そのユーザー名のIDをloginattemptテーブルに入れ、間違ったパスワードメッセージを表示したいと考えています。誰かが私を助けてください。
1 に答える
2
userIdentity.phpで、データをテーブルに保存します。
public function authenticate() {
$user = User::model()->findByAttributes(array('username' => $this->username));
if ($user === null) {
$this->errorCode = self::ERROR_USERNAME_INVALID;
}
elseif($user->password !== crypt($this->password, $salt))
{ // save $user->id in attempt table here .
$this->errorCode = self::ERROR_PASSWORD_INVALID;
}else{
//set id
}
そして、認証関数がsetErrorと呼ばれるファイル内。
$this->_identity = new UserIdentity($this->username, $this->password);
if (!$this->_identity->authenticate())
if ($this->_identity->errorCode === UserIdentity::ERROR_USERNAME_INVALID) {
$this->addError('password', 'Incorrect email Id');
}elseif($this->_identity->errorCode === UserIdentity::ERROR_PASSWORD_INVALID){
$this->addError('password', 'Incorrect Password');
}
于 2012-11-24T05:52:16.907 に答える