Something Wrong With Saving Changes

Hi, guys. I want to let user change his password. I’m at my wits end with this simple piece of code:


    public function actionChangepass()

	{


              $model=Register::model()->findByPk(Yii::app()->user->id);

   		// collect user input data

              if(isset($_POST['Register']))

		{


                   if($_POST['Register']['newpassword']!=$_POST['Register']['appnewpassword'])

                   {

                      Yii::app()->user->setFlash('changepass','Confirm password once more.');

                      $model->password='';

                      $this->render('chpass',array('model'=>$model));exit;

                   }

                   if(($model->password)!=$model->hashPassword($_POST['Register']['password'],$model->salt))

                   {

                     Yii::app()->user->setFlash('changepass','Password is invalid.');

                     $model->password='';

                     $this->render('chpass',array('model'=>$model));exit;

                   }

                   else

                   {

                     $model->password=$model->hashPassword($_POST['Register']['newpassword'],$model->salt);

                     $model->update();

                     $this->redirect(Yii::app()->user->returnUrl);

                   }

		}

                else

                {

                 $model->password='';

                 $this->render('chpass',array('model'=>$model));

                } 

}

Please, help me!

It saves abracadabra hash in password field, instead of hashed new password.