Last active
November 23, 2015 06:41
-
-
Save kbparagua/d820ac012514c7fa428b to your computer and use it in GitHub Desktop.
This file contains 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
VALID_EMAIL_REGEX = /\A([\w+\-].?)+@[a-z\d\-]+(\.[a-z]+)*\.[a-z]+\z/i | |
def authenticate email, password | |
user = User.find_by_email email | |
if password.present? && valid_email?(email) && user.present? && correct_password?(user, password) | |
user | |
else | |
false | |
end | |
end | |
def valid_email? email | |
email =~ VALID_EMAIL_REGEX | |
end | |
def correct_password? user, password | |
encrypted_password = BCrypt::Password.new password | |
user.encrypted_password == encrypted_password | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment