Class: Hello::Encryptors::Complex

Inherits:
Simple
  • Object
show all
Defined in:
lib/hello/encryptors/complex.rb

Instance Method Summary collapse

Methods inherited from Simple

#pair, #single

Constructor Details

#initialize(cost = nil) ⇒ Complex

Returns a new instance of Complex.



4
5
6
7
8
9
10
11
12
# File 'lib/hello/encryptors/complex.rb', line 4

def initialize(cost=nil)
  require 'bcrypt'
  cost ||= Rails.env.test? ? 1 : 10
  BCrypt::Engine.cost = cost
rescue LoadError
  s = "your Gemfile needs: gem 'bcrypt'"
  puts [s.red, s.yellow, s.green]
  raise
end

Instance Method Details

#encrypt(string) ⇒ Object



14
15
16
# File 'lib/hello/encryptors/complex.rb', line 14

def encrypt(string)
  BCrypt::Password.create(string).to_s
end

#match(string, digest) ⇒ Object



18
19
20
21
22
# File 'lib/hello/encryptors/complex.rb', line 18

def match(string, digest)
  BCrypt::Password.new(digest) == string
rescue BCrypt::Errors::InvalidHash
  false
end