hi every body....
I need help..
I have the following code in a user model. But when i try to autenticate an
user always returns nil, my session controller calls the autenticate method.
I proves comparing only the database password with new encrypted password
but always returns nil. The database password was encryted with the same
encrypt method. I dont know what i need to do.
TNKS a lot..
# Authenticates a user by their login name and unencrypted password. Returns
the user or nil.
*
def self*.authenticate(login, password)
u = find_by_login(login) # need to get the salt and user_password
u && u.authenticated?(password) ? u :* nil
end
*
# Encrypts some data with the salt.
*
def self*.encrypt(password, salt)
Digest::SHA1.hexdigest("--#{salt}--#{password}--")
*
end
*
# Encrypts the password with the user salt
*
def* encrypt(password)
*
self*.class.encrypt(password, salt)
*
end
*
*
def* authenticated?(password)
user_password == encrypt(password)
*
end
*
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
On 7 Nov 2008, at 22:57, Margareth Florián wrote:> hi every body.... > > I need help.. > I have the following code in a user model. But when i try to > autenticate an user always returns nil, my session controller calls > the autenticate method. I proves comparing only the database > password with new encrypted password but always returns nil. The > database password was encryted with the same encrypt method. I dont > know what i need to do. > TNKS a lot.."When you have excluded the impossible, whatever remains, however improbable, must be the truth.". How are you creating/saving users? Fred --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---