# Form Change Old Password

**URL:** <https://www.ruby-forum.com/t/form-change-old-password/105581>\
**Category:** Rails\
**Created:** [May 31, 2007, 12:12pm UTC](https://www.ruby-forum.com/t/form-change-old-password/105581 "2007-05-31T12:12:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jamal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/35a633/32.png) [@jamal](https://www.ruby-forum.com/u/jamal)\
**Post date:** [May 31, 2007, 12:12pm UTC](https://www.ruby-forum.com/t/form-change-old-password/105581/1 "2007-05-31T12:12:32Z")

</div>

Hello there,

I want my users to be able to change their password.

I wrote the code below but I need help to add error if the old password  
he posted did not match the current password he have.

In the controller I have:  
def my\_profile\_password  
return true unless request.post?  
@user = current\_user  
if @user.check\_password(params[:old\_password])  
@user.update\_attributes(params[:user])  
if @user.update  
end  
end  
end

and in my model:  
def check\_password(password)  
if self.password == User.encrypt(password)  
true  
end  
end

PS: I know I should use @user.errors.add("", “Old password is wrong”),  
but where should I place it in my code?

I tried within check\_password but this is not working ☹

I appreciate any help 😃

---

<div class="post-metadata">

**Author:** ![jamal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/35a633/32.png) [@jamal](https://www.ruby-forum.com/u/jamal)\
**Post date:** [May 31, 2007, 12:23pm UTC](https://www.ruby-forum.com/t/form-change-old-password/105581/2 "2007-05-31T12:23:16Z")

</div>

Rails server is weird, things are not working, when I do changes and put  
everything back like it was, it then starts working again??

This is not the first time its happening!
