class MultiPassword::Strategies::BCrypt

Public Instance Methods

create(password, options = {}) click to toggle source
# File lib/multi_password/strategies/bcrypt.rb, line 11
def create(password, options = {})
  ::BCrypt::Password.create(password, validate_options(options)).to_s
end
validate_options(options) click to toggle source
# File lib/multi_password/strategies/bcrypt.rb, line 19
def validate_options(options)
  return options if options.empty?

  cost = options[:cost]

  if !cost.is_a?(Integer) || cost < 4 || cost > 31
    raise InvalidOptions.new('bcrypt', 'cost must be an integer between 4 and 31')
  end

  options
end
verify(password, encrypted_password) click to toggle source
# File lib/multi_password/strategies/bcrypt.rb, line 15
def verify(password, encrypted_password)
  ::BCrypt::Password.new(encrypted_password) == password
end