Skip to content

Instantly share code, notes, and snippets.

@kbparagua
Last active November 23, 2015 06:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kbparagua/5e3bcfe1ff51312fb2a8 to your computer and use it in GitHub Desktop.
Save kbparagua/5e3bcfe1ff51312fb2a8 to your computer and use it in GitHub Desktop.
def authenticate email, password
user = User.find_by_email email
if password.nil? || email !=~ /\A([\w+\-].?)+@[a-z\d\-]+(\.[a-z]+)*\.[a-z]+\z/i || user.nil?
return false
end
encrypted_password = BCrypt::Password.new password
if user.encrypted_password == encrypted_password
user
else
false
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment