Changepassword Not Working

I am currently working on changing user password but it keeps on telling that I entered a wrong password. Anyone who could figure it out? I am a newbie here so please help me.

This is my UserTableController:

public function actionChangePassword($id)



		$this->layout = 'column1';

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

		$tempModel = UserTable::model()->findByPk($id);

		$model = new UserTable;












			if(md5(md5($model->oldPassword) . Yii::app()->params["salt"]) === $tempModel->password)


				$tempModel->password = $model->hashPassword($model->newPassword);


				Yii::app()->user->setFlash('success', 'Password updated successfully.');





				Yii::app()->user->setFlash('error', "Wrong Password");



			$this->redirect(array('changePassword', 'id'=>$id));








And this is my Usertable model:

	public function rules()


		// NOTE: you should only define rules for those attributes that

		// will receive user inputs.

		return array(

			array('first_name, middle_name, last_name, username, password, sector, user_role', 'required'),

			//array('rePassword', 'required', 'except'=>'update'),

			array('oldPassword, newPassword, rePassword', 'required', 'on'=>'changePassword'),

			//array('rePassword', 'required', 'on'=>'register, changePassword'),

            		array('rePassword', 'compare', 'compareAttribute'=>'password', 'on'=>'changePassword', 'message'=>'Passwords must match.'),

            		array('rePassword', 'compare', 'compareAttribute'=>'newPassword', 'on'=>'changePassword', 'message'=>'It does not match with New Password'),

            		array('password, rePassword, oldPassword, newPassword', 'length', 'min'=>4),

			array('first_name, middle_name, last_name, username, password', 'length', 'max'=>20),

			array('sector, user_role', 'length', 'max'=>100),

			// The following rule is used by search().

			// Please remove those attributes that should not be searched.

			array('first_name, middle_name, last_name, username, password, sector, user_role', 'safe', 'on'=>'search'),




	 * @return array relational rules.


	public function relations()


		// NOTE: you may need to adjust the relation name and the related

		// class name for the relations automatically generated below.

		return array(



	public function hashPassword($password)


        return md5(md5($password) . Yii::app()->params["salt"]);


	 public function beforeSave()


        if($this->rePassword != '')

            $this->password = md5(md5($this->rePassword).Yii::app()->params["salt"]);

        return true;



What do you think is missing?

Basically you need a function that checks if the pattern of your hashed password is the same with the password you are currently passing as POST

How can i do that exactly?

Be sure your new password saved in database and in UserIdentity which field used for comparing password?