In yii i am creating login module. I want to give access to users only if username and passwords are correct and need to store this user's id into 'Success' table. But when only username is correct and password is wrong,i want to store that user's id into 'attempt' table in order to give only 3 chance to him for entering correct password. But when i am implementing this,when password is wrong entry doesnt get enterd into attempt table. i had created ActionLogin() method as-
public function actionLogin()
{
    $model=new LoginForm;
    $command = Yii::app()->db->createCommand();
    // if it is ajax validation request
    if(isset($_POST['ajax']) && $_POST['ajax']==='login-form')
    {
        echo CActiveForm::validate($model);
        Yii::app()->end();
    }
    // collect user input data
    if(isset($_POST['LoginForm']))
    {
         $model->attributes=$_POST['LoginForm'];
         // validate user input and redirect to the previous page if valid
         if ($model->validate()) 
         {
            if($model->login()) {
                      $command->insert('attempt', array(
                      'id'=>Yii::app()->user->getId(),
                       ));
                      $this->redirect(Yii::app()->user->returnUrl);
             }  
            if(!$model->login())
            {            
            $command->insert('attempt', array(
            'id'=>Yii::app()->user->getId(),
                   ));
             } 
            }
     }
    // display the login form
    $this->render('login',array('model'=>$model));
}
What changes i need to do in order to make entry of user's id into attempt table when password is wrong. Please help me.