module Authenticate::Crypto::BCrypt

All crypto providers must implement encrypt(secret) and match?(secret, encrypted)

Public Instance Methods

cost() click to toggle source
# File lib/authenticate/crypto/bcrypt.rb, line 17
def cost
  @cost ||= ::BCrypt::Engine::DEFAULT_COST
end
cost=(val) click to toggle source
# File lib/authenticate/crypto/bcrypt.rb, line 21
def cost=(val)
  if val < ::BCrypt::Engine::MIN_COST
    msg = "bcrypt cost cannot be set below the engine's min cost (#{::BCrypt::Engine::MIN_COST})"
    raise ArgumentError.new(msg), msg
  end
  @cost = val
end
encrypt(secret) click to toggle source
# File lib/authenticate/crypto/bcrypt.rb, line 8
def encrypt(secret)
  ::BCrypt::Password.create secret, cost: cost
end
match?(secret, encrypted) click to toggle source
# File lib/authenticate/crypto/bcrypt.rb, line 12
def match?(secret, encrypted)
  return false unless encrypted.present?
  ::BCrypt::Password.new(encrypted) == secret
end