# Validates\_confirmation\_of not working - now in right place

**URL:** <https://www.ruby-forum.com/t/validates-confirmation-of-not-working-now-in-right-place/102685>\
**Category:** Rails\
**Created:** [February 11, 2007, 1:11am UTC](https://www.ruby-forum.com/t/validates-confirmation-of-not-working-now-in-right-place/102685 "2007-02-11T01:11:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![j-merrill](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/aeb1de/32.png) [@j-merrill](https://www.ruby-forum.com/u/j-merrill)\
**Post date:** [February 11, 2007, 1:11am UTC](https://www.ruby-forum.com/t/validates-confirmation-of-not-working-now-in-right-place/102685/1 "2007-02-11T01:11:55Z")

</div>

well, here I am again 🙂

validates\_confirmation\_of is not working

heres my model

class User \< ActiveRecord::Base  
attr\_accessor :password  
attr\_accessible :email, :first\_name, :last\_name, :screen\_name,  
:password  
validates\_confirmation\_of :password  
validates\_presence\_of :email, :first\_name, :last\_name, :screen\_name,  
:password  
validates\_format\_of(:email,  
:with =\>  
/^([^@\s]+)@((?:[-a-z0-9]+.)+[a-z]{2,})$/i,  
:on =\> :create,  
:message=\>“has an invalid format”)  
#validates the uniqueness of email and screen name  
validates\_uniqueness\_of :email, :screen\_name

#end

def before\_create  
logger.info(“password set to:”+password)  
salt = [Array.new(6) {rand(256).chr}.join].pack(“m”).chomp  
self.password\_salt, self.password\_hash =  
salt, Digest::SHA256.hexdigest(password+salt)

end

#Authenticate a user  
def self.authenticate(email, password)

```
user = User.find(:first, :conditions => ['email = ?', email])
 if user.blank? ||
    Digest::SHA256.hexdigest(password+ user.password_salt) !=

```

user.password\_hash

```
    raise "UserName or password invalid"
 end
 user

```

end

end

and my view

Email  
\<%= text\_field 'user', 'email' %\>

Screen Name  
\<%= text\_field 'user', 'screen\_name' %\>

First Name  
\<%= text\_field 'user', 'first\_name' %\>

Last Name  
\<%= text\_field 'user', 'last\_name' %\>

Password  
\<%= password\_field 'user', 'password' %\>

Password Confirmation  
\<%= password\_field 'user', 'password\_confirmation'%\>

however if I set differnt passwords in user creation it let me save the  
user ☹

---

<div class="post-metadata">

**Author:** ![j-merrill](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/aeb1de/32.png) [@j-merrill](https://www.ruby-forum.com/u/j-merrill)\
**Post date:** [February 11, 2007, 1:23am UTC](https://www.ruby-forum.com/t/validates-confirmation-of-not-working-now-in-right-place/102685/2 "2007-02-11T01:23:13Z")

</div>

J. mp wrote:

> well, here I am again 🙂
> 
> validates\_confirmation\_of is not working

> \<%= password\_field ‘user’, ‘password’ %\>
> 
> Password Confirmation  
> \<%= password\_field 'user', 'password\_confirmation'%\>

just to add a logger info

Parameters: {“user”=\>{“password\_confirmation”=\>“12922eddsd”,  
“screen\_name”=\>“kdskdk”, “first\_name”=\>“kdskk”, “last\_name”=\>“dskkd”,  
“password”=\>“skdks”, “email”=\>“removed\_email\_address@domain.invalid”}, “commit”=\>“Create”,  
“action”=\>“add\_user”, “controller”=\>“admin/user”}

it is the the request, but not working ☹

---

<div class="post-metadata">

**Author:** ![j-merrill](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/aeb1de/32.png) [@j-merrill](https://www.ruby-forum.com/u/j-merrill)\
**Post date:** [February 11, 2007, 1:37am UTC](https://www.ruby-forum.com/t/validates-confirmation-of-not-working-now-in-right-place/102685/3 "2007-02-11T01:37:33Z")

</div>

J. mp wrote:

> J. mp wrote:
> 
> > well, here I am again 🙂
> > 
> > validates\_confirmation\_of is not working
> 
> > \<%= password\_field ‘user’, ‘password’ %\>
> > 
> > Password Confirmation  
> > \<%= password\_field 'user', 'password\_confirmation'%\>
> 
> just to add a logger info
> 
> Parameters: {“user”=\>{“password\_confirmation”=\>“12922eddsd”,  
> “screen\_name”=\>“kdskdk”, “first\_name”=\>“kdskk”, “last\_name”=\>“dskkd”,  
> “password”=\>“skdks”, “email”=\>“removed\_email\_address@domain.invalid”}, “commit”=\>“Create”,  
> “action”=\>“add\_user”, “controller”=\>“admin/user”}
> 
> it is the the request, but not working ☹

thanks all,  
found the problem 🙂 and the solution:

attr\_accessible :email, :first\_name, :last\_name, :screen\_name,  
:password,:password\_confirmation

missedthe password\_conmfirmation on attr\_accessible list 🙂

---

<div class="post-metadata">

**Author:** ![j-merrill](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/aeb1de/32.png) [@j-merrill](https://www.ruby-forum.com/u/j-merrill)\
**Post date:** [February 11, 2007, 1:41am UTC](https://www.ruby-forum.com/t/validates-confirmation-of-not-working-now-in-right-place/102685/4 "2007-02-11T01:41:14Z")

</div>

On Sun, 11 Feb 2007, J. mp wrote:

> well, here I am again 🙂
> 
> validates\_confirmation\_of is not working

What does the code look like where you create the new user record?

David

–  
Q. What is THE Ruby book for Rails developers?  
A. RUBY FOR RAILS by David A. Black ([http://www.manning.com/black](http://www.manning.com/black))  
(See what readers are saying! [http://www.rubypal.com/r4rrevs.pdf](http://www.rubypal.com/r4rrevs.pdf))  
Q. Where can I get Ruby/Rails on-site training, consulting, coaching?  
A. Ruby Power and Light, LLC ([http://www.rubypal.com](http://www.rubypal.com))

---

<div class="post-metadata">

**Author:** ![j-merrill](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/aeb1de/32.png) [@j-merrill](https://www.ruby-forum.com/u/j-merrill)\
**Post date:** [February 11, 2007, 1:44am UTC](https://www.ruby-forum.com/t/validates-confirmation-of-not-working-now-in-right-place/102685/5 "2007-02-11T01:44:19Z")

</div>

unknown wrote:

> On Sun, 11 Feb 2007, J. mp wrote:
> 
> > well, here I am again 🙂
> > 
> > validates\_confirmation\_of is not working
> 
> What does the code look like where you create the new user record?
> 
> David
> 
> –  
> Q. What is THE Ruby book for Rails developers?  
> A. RUBY FOR RAILS by David A. Black ([http://www.manning.com/black](http://www.manning.com/black))  
> (See what readers are saying! [http://www.rubypal.com/r4rrevs.pdf](http://www.rubypal.com/r4rrevs.pdf))  
> Q. Where can I get Ruby/Rails on-site training, consulting, coaching?  
> A. Ruby Power and Light, LLC ([http://www.rubypal.com](http://www.rubypal.com))

thanks David but I already realized the problem:  
missed the password\_conmfirmation on attr\_accessible list 🙂

---

<div class="post-metadata">

**Author:** ![j-merrill](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/aeb1de/32.png) [@j-merrill](https://www.ruby-forum.com/u/j-merrill)\
**Post date:** [February 11, 2007, 1:43am UTC](https://www.ruby-forum.com/t/validates-confirmation-of-not-working-now-in-right-place/102685/6 "2007-02-11T01:43:14Z")

</div>

On Sat, 10 Feb 2007, removed\_email\_address@domain.invalid wrote:

> On Sun, 11 Feb 2007, J. mp wrote:
> 
> > well, here I am again 🙂
> > 
> > validates\_confirmation\_of is not working
> 
> What does the code look like where you create the new user record?

Never mind – I just saw that you found the problem 🙂

David

–  
Q. What is THE Ruby book for Rails developers?  
A. RUBY FOR RAILS by David A. Black ([http://www.manning.com/black](http://www.manning.com/black))  
(See what readers are saying! [http://www.rubypal.com/r4rrevs.pdf](http://www.rubypal.com/r4rrevs.pdf))  
Q. Where can I get Ruby/Rails on-site training, consulting, coaching?  
A. Ruby Power and Light, LLC ([http://www.rubypal.com](http://www.rubypal.com))
