How to update a user password

Hi,

I am very new to Yii and I am trying to implement Password Change option to

the users in my project.

I have created a separate view and controller for this.

This is my view (_form)

<div class="row">

	&lt;?php echo CHtml::label(&quot;Current Password&quot;,'old_pwd');?&gt; 


	&lt;?php echo CHtml::passwordField(&quot;old_pwd&quot;);?&gt;


	


&lt;/div&gt;





&lt;div class=&quot;row&quot;&gt; 


	&lt;?php echo CHtml::label(&quot;New Password&quot;,'new_pwd');?&gt; 


	&lt;?php echo CHtml::passwordField(&quot;new_pwd&quot;);?&gt; 


&lt;/div&gt; 





&lt;div class=&quot;row&quot;&gt; 


	&lt;?php echo CHtml::label(&quot;Confirm New Password&quot;,'new_pwd_rept');?&gt; 


	&lt;?php echo CHtml::passwordField(&quot;new_pwd_rept&quot;);?&gt; 


&lt;/div&gt;

From this _form I need to call a function(changePassword) in the controller to update the user password

This is my function in the controller

public function changePassword()

{





	echo &quot;&lt;br&gt;Inside Action&lt;br&gt;&quot;;


	&#036;this-&gt;_old_pwd = SHA1(&#036;_POST['old_pwd']);


	&#036;this-&gt;_new_pwd = SHA1(&#036;_POST['new_pwd']);


	&#036;this-&gt;_new_pwd_repeat = SHA1(&#036;_POST['new_pwd_rept']);


	if((Yii::app()-&gt;user-&gt;password) === _old_pwd)


	{


		if(_new_pwd === _new_pwd_repeat)


		{


			echo &quot;&lt;br&gt;Inside Update&lt;br&gt;&quot;;


			User::model()-&gt;updateByPk(&#036;user-&gt;id,array('password'=&gt; _new_pwd));


		}


		else


		{


			//echo array('confirm'=&gt;'New Passwords Entered is not Matched...&#33;?');


			echo &quot;New Passwords Entered is not Matched...&quot;;


		}


					


	}


	else


	{


		//echo array('confirm'=&gt;'Current Password Typed is Incorrect...&#33;?');		


		echo &quot;Current Password Typed is Incorrect....&quot;;	


	}


		


}

Whether my approach is correct? If not pls help me to implement it in the right way.

Thanking you

Sumesh

Try to search the forum… .there where some posts about this…

One is this - http://www.yiiframework.com/forum/index.php?/topic/12229-