class MultiPassword::Strategies::SCrypt

Public Instance Methods

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

  key_len = options[:key_len]
  max_time = options[:max_time]
  max_mem = options[:max_mem]

  if key_len && (!key_len.is_a?(Integer) || key_len < 16 || key_len > 512)
    raise InvalidOptions.new('scrypt', 'key_len must be an integer between 16 and 512')
  end

  if max_time && (!max_time.is_a?(Numeric) || max_time < 0 || max_time > 2)
    raise InvalidOptions.new('scrypt', 'max_time must be a number between 0 and 2')
  end

  if max_mem && (!max_mem.is_a?(Integer) || max_mem < 0 || max_mem > 256)
    raise InvalidOptions.new('scrypt', 'max_mem must be an integer between 0 and 256')
  end

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