Skip to content

Instantly share code, notes, and snippets.

@aratak
Created June 19, 2015 10:02
Show Gist options
  • Save aratak/9ad69d57cd6dc6e9e09d to your computer and use it in GitHub Desktop.
Save aratak/9ad69d57cd6dc6e9e09d to your computer and use it in GitHub Desktop.
encryptor.rb
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