On Jan 3, 4:37 pm, radu puspana <[email protected]> wrote:
> user.each do |correct_user|
> expected_password = User.encrypted_password(password, correct_user.salt)
> if correct_user.hashed_password == expected_password
> idx = user.index(correct_user)
> return user[idx]
> end
> end
This is somewhat unwieldy - why the busines with index when you could
just return correct_user ? Even better, use a method like detect - the
code above is equivalent to
user.detect {|current_user| current_user == User.encrypt(password,
current_user)}
You'll also find your code reads more easily if variables that contain
collections are pluralised (ie users = User.find :all rather than user
= User.find( :all))
This shouldn't change the result of the code however. Seems to me that
the data in your table might just be bad (or you're typing in the
wrong password) - What is the value of User.encrypted_password
( 'gica1', User.find(4).salt) ?
Having users with the same name is really rather weird - every website
I can think of requires usernames to be unique
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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.