Skip to content

Instantly share code, notes, and snippets.

@kelhusseiny
Created April 20, 2012 04:49
Show Gist options
  • Save kelhusseiny/2426082 to your computer and use it in GitHub Desktop.
Save kelhusseiny/2426082 to your computer and use it in GitHub Desktop.
def self.authenticate(username_or_email="", login_password="")
if EMAIL_REGEX.match(username_or_email)
user = User.find_by_email(username_or_email)
else
user = User.find_by_username(username_or_email)
end
if user && user.match_password(login_password)
return user
else
return false
end
end
def match_password(login_password="")
encrypted_password == BCrypt::Engine.hash_secret(login_password, salt)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment