Skip to content

Instantly share code, notes, and snippets.

@jhancock
Created December 30, 2008 22:57
Show Gist options
  • Save jhancock/41794 to your computer and use it in GitHub Desktop.
Save jhancock/41794 to your computer and use it in GitHub Desktop.
# 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