validates_confirmation_of not working

J

J. mp

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,
:eek:n => :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


<p><label for="email">Email</label><br/>
<%= text_field 'user', 'email' %></p>

<p><label for="screen_name">Screen Name</label><br/>
<%= text_field 'user', 'screen_name' %></p>

<p><label for="first_name">First Name</label><br/>
<%= text_field 'user', 'first_name' %></p>

<p><label for="last_name">Last Name</label><br/>
<%= text_field 'user', 'last_name' %></p>


<p><label for="password">Password</label><br/>
<%= password_field 'user', 'password' %></p>

<p><label for="password_confirmation">Password Confirmation</label><br/>
<%= password_field 'user', 'password_confirmation'%></p>


however if I set differnt passwords in user creation it let me save the
user :(
 
A

Austin Ziegler

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 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,999
Messages
2,570,243
Members
46,835
Latest member
lila30

Latest Threads

Top