# Changing password not validating\_confirmation\_of

**URL:** <https://www.ruby-forum.com/t/changing-password-not-validating-confirmation-of/125757>\
**Category:** Rails\
**Created:** [January 11, 2008, 7:30pm UTC](https://www.ruby-forum.com/t/changing-password-not-validating-confirmation-of/125757 "2008-01-11T19:30:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![student](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ecc23a/32.png) [@student](https://www.ruby-forum.com/u/student)\
**Post date:** [January 11, 2008, 7:30pm UTC](https://www.ruby-forum.com/t/changing-password-not-validating-confirmation-of/125757/1 "2008-01-11T19:30:05Z")

</div>

Cargo-culting isn’t working…

User:  
attr\_reader :password # Virtual attribute

validates\_presence\_of :username  
validates\_uniqueness\_of :username

attr\_accessor :password\_confirmation  
validates\_confirmation\_of :password

& etc from AWDR with use of a hashed password

UserController:  
def change\_password  
user = User.find(session[:user\_id])  
if request.post?  
opw = params[:user][:old\_password]  
npw = params[:user][:password]  
if user.verify\_password(opw) and opw != npw  
user.password = npw  
user.save  
else  
flash.now[:notice] = “Bad Password”  
end  
end  
end

change\_password.rhtml:

\<%= error\_messages\_for 'user' %\> Changing Password

```
<% form_for :user do |form| %>
  <p>
    <label for="user_old_password">Old Password:</label>
    <%= form.text_field :old_password, :size => 40 %>
  </p>

  <p>
    <label for="user_password">Password:</label>
    <%= form.text_field :password, :size => 40 %>
  </p>

  <p>
    <label for="user_password_confirmation">Confirm:</label>
    <%= form.text_field :password_confirmation, :size => 40 %>
  </p>

  <%= submit_tag "Change Password", :class => "submit" %>
<% end %>

```

I’m reasonably certain that validates\_confirmation\_of is not being  
invoked, but I have no idea why. Assigning user.password\_confirmation  
does not help. The parameters are coming in just fine.

---

<div class="post-metadata">

**Author:** ![student](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ecc23a/32.png) [@student](https://www.ruby-forum.com/u/student)\
**Post date:** [January 11, 2008, 9:34pm UTC](https://www.ruby-forum.com/t/changing-password-not-validating-confirmation-of/125757/2 "2008-01-11T21:34:12Z")

</div>

I’m not sure if this will fix your particular issue, but you may want  
to remove your own attr\_accessor for the password\_confirmation  
attribute, since validates\_confirmation\_of provides its own  
implementation.

---

<div class="post-metadata">

**Author:** ![student](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ecc23a/32.png) [@student](https://www.ruby-forum.com/u/student)\
**Post date:** [January 11, 2008, 10:34pm UTC](https://www.ruby-forum.com/t/changing-password-not-validating-confirmation-of/125757/3 "2008-01-11T22:34:07Z")

</div>

The book has it & discussions here seem to confirm that it is  
required. I’ll check, though.
