Alright so I have begun using yii and completed the blog tutorial and am now trying a very simple website on my own. Unfortunately I have run into a issue with the userIdentity I created a model for a User which holds things like username, passwordhash, passwordsalt, attempted tries etc. I keep getting parsing errors on
on failed logins. I am not sure how I should be able to do this...Any suggestions? Below is my UserIdentity
$user->tries = $user->tries + 1; $user->save();
on failed logins. I am not sure how I should be able to do this...Any suggestions? Below is my 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 { /** * 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. */ private $_id; public function authenticate() { $user=User::model()->findByAttributes(array('name'=>$this->username)); if ($user === null) $this->errorCode=self::ERROR_USERNAME_INVALID; else if ($user->passwordHash!==hash('sha512',$this->password . $user->passwordSalt)){ $user->tries = $user->tries + 1; $user->save(); $this->errorCode=self::ERROR_PASSWORD_INVALID; } else if ($user->tries >= 3) $this->errorCode=self::ERROR_STATUS_LOCKED; else { $this ->_id=$user->Id; $this ->setState('title',$user->title); $this ->errorCode=self::ERROR_NONE; /*$auth = Yii::app()->authManager; if(!$auth->isAssigned($user->role, $this->_id)) { if($auth->assign($user->role, $this->_id)) { Yii::app()->authManager->save(); } }*/ } return !$this->errorCode; } public function getId() { return $this-> _id; } }