Class: MultiPassword::Strategies::Argon2

Inherits:
Object
  • Object
show all
Includes:
MultiPassword::Strategy
Defined in:
lib/multi_password/strategies/argon2.rb

Instance Method Summary collapse

Methods included from MultiPassword::Strategy

included

Instance Method Details

#create(password, options = {}) ⇒ Object



11
12
13
# File 'lib/multi_password/strategies/argon2.rb', line 11

def create(password, options = {})
  ::Argon2::Password.new(validate_options(options)).create(password)
end

#validate_options(options) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/multi_password/strategies/argon2.rb', line 19

def validate_options(options)
  return options if options.empty?

  t_cost = options[:t_cost]
  m_cost = options[:m_cost]

  if t_cost && (!t_cost.is_a?(Integer) || t_cost < 1 || t_cost > 750)
    raise InvalidOptions.new('argon2', 't_cost must be an integer between 1 and 750')
  end

  if m_cost && (!m_cost.is_a?(Integer) || m_cost < 1 || m_cost > 31)
    raise InvalidOptions.new('argon2', 'm_cost must be an integer between 1 and 31')
  end

  options
end

#verify(password, encrypted_password) ⇒ Object



15
16
17
# File 'lib/multi_password/strategies/argon2.rb', line 15

def verify(password, encrypted_password)
  ::Argon2::Password.verify_password(password, encrypted_password)
end