Class: MultiPassword::Strategies::BCrypt

Inherits:
Object
  • Object
show all
Includes:
MultiPassword::Strategy
Defined in:
lib/multi_password/strategies/bcrypt.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/bcrypt.rb', line 11

def create(password, options = {})
  ::BCrypt::Password.create(password, validate_options(options)).to_s
end

#validate_options(options) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# 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) ⇒ Object



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

def verify(password, encrypted_password)
  ::BCrypt::Password.new(encrypted_password) == password
end