Created
June 19, 2015 10:02
-
-
Save aratak/9ad69d57cd6dc6e9e09d to your computer and use it in GitHub Desktop.
encryptor.rb
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
require 'bcrypt' | |
module Encryptor | |
def digest(password) | |
::BCrypt::Password.create(password, cost: 3).to_s | |
end | |
module_function :digest | |
def compare(encrypted_password, password) | |
return false if encrypted_password.blank? | |
bcrypt = ::BCrypt::Password.new(encrypted_password) | |
password = ::BCrypt::Engine.hash_secret(password, bcrypt.salt) | |
password.to_s == encrypted_password.to_s | |
end | |
module_function :compare | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment