Created
December 30, 2008 22:57
-
-
Save jhancock/41794 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Authenticates a user by their email and cleartext password. Returns a User or nil. | |
def self.authenticate(email, password) | |
if user = self.activated.first(:email => email) | |
if validate_password(password, user.password_hash, user.password_salt) | |
return user | |
end | |
end | |
false | |
end | |
# returns true if the password is correct | |
def self.validate_password(password, password_hash, password_salt) | |
password_hash == OpenSSL::Digest::SHA1.hexdigest("--#{password_salt}--#{password}--") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment