class BcryptHmac::Encryptor
Public Class Methods
compare(encrypted_password, password, _stretches = nil, _salt = nil, pepper = nil)
click to toggle source
# File lib/bcrypt_hmac.rb, line 18 def self.compare(encrypted_password, password, _stretches = nil, _salt = nil, pepper = nil) saved_password = BCrypt::Password.new(encrypted_password) proposed_password = prepare_for_bcrypt(password, pepper.to_s) saved_password == proposed_password end
digest(password, stretches = nil, _salt = nil, pepper = nil)
click to toggle source
# File lib/bcrypt_hmac.rb, line 8 def self.digest(password, stretches = nil, _salt = nil, pepper = nil) pre_bcrypt_hash = prepare_for_bcrypt(password, pepper.to_s) if stretches BCrypt::Password.create(pre_bcrypt_hash, cost: stretches.to_i) else BCrypt::Password.create(pre_bcrypt_hash) end end
Private Class Methods
prepare_for_bcrypt(password, hmac_key)
click to toggle source
# File lib/bcrypt_hmac.rb, line 26 def self.prepare_for_bcrypt(password, hmac_key) Base64.encode64(sha256_hash(password, hmac_key)) end
sha256_hash(password, hmac_key)
click to toggle source
# File lib/bcrypt_hmac.rb, line 31 def self.sha256_hash(password, hmac_key) sha256 = OpenSSL::Digest.new('sha256') OpenSSL::HMAC.digest(sha256, hmac_key, password) end