# Validates\_confirmation\_of not working

**URL:** <https://www.ruby-forum.com/t/validates-confirmation-of-not-working/85186>\
**Category:** Ruby\
**Created:** [February 11, 2007, 12:41am UTC](https://www.ruby-forum.com/t/validates-confirmation-of-not-working/85186 "2007-02-11T00:41:07Z")\
**Posts on this page:** 2\
**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, 12:41am UTC](https://www.ruby-forum.com/t/validates-confirmation-of-not-working/85186/1 "2007-02-11T00:41:07Z")

</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:09am UTC](https://www.ruby-forum.com/t/validates-confirmation-of-not-working/85186/2 "2007-02-11T01:09:13Z")

</div>

On 2/10/07, J. mp [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> validates\_confirmation\_of is not working

This is a rails-specific question asked on the general Ruby mailing  
list (which is bidirectionally mirrored to [ruby-forum.com](http://ruby-forum.com) and the  
comp.lang.ruby newsgroup); you’re more likely to get a useful topical  
answer to Rails questions on the proper Rails fora.

-austin
