Created
January 27, 2011 21:36
-
-
Save namelessjon/799333 to your computer and use it in GitHub Desktop.
Example showing the use of the bcrypt password api
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
class User | |
def self.authenticate(email, password) | |
user = find_by_email(email) | |
if user && BCrypt::Password.new(user.password_hash) == password | |
user | |
else | |
nil | |
end | |
end | |
def encrypt_password | |
if password.present? | |
self.password_hash = BCrypt::Password.create(password) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment