I’ve been looking at a project for a login module, but I’m not sure exactly what this helper method is doing:
def self.authenticate(login, pass)
u = User.first(:login => login)
return nil if u.nil?
return u if User.encrypt(pass, u.salt) == u.hashed_password
nil
end
Why not instead of:
u = User.first(:login => login)
…you do something like:
u = self.login
Thanks!
The
firsthelper method locates the first record in your database that matches the specified criteria. It’s semantically equivalent to the following SQL statement:The code after
u = User.first(:login => login)does the following:1. Checks to see if there is a user returned with the specified login
2. Returns the User object if the passwords match.