Class: SequelAuth::Providers::Bcrypt

Inherits:
Object
  • Object
show all
Defined in:
lib/providers/bcrypt.rb

Class Method Summary collapse

Class Method Details

.costObject



8
9
10
# File 'lib/providers/bcrypt.rb', line 8

def cost
  @cost ||= ::BCrypt::Engine.cost
end

.cost=(val) ⇒ Object

Raises:

  • (ArgumentError)


12
13
14
15
# File 'lib/providers/bcrypt.rb', line 12

def cost=(val)
  raise ArgumentError,"cost < #{min_cost} not allowed!" if val < min_cost
  @cost = val
end

.encrypt(password) ⇒ Object

Raises:

  • (ArgumentError)


17
18
19
20
# File 'lib/providers/bcrypt.rb', line 17

def encrypt(password)
  raise ArgumentError, "password not a valid string" if !password.is_a?(String) || password.strip.empty?
  ::BCrypt::Password.create(password, cost: cost)
end

.matches?(hash, password) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
25
26
# File 'lib/providers/bcrypt.rb', line 22

def matches?(hash,password)
  ::BCrypt::Password.new(hash)==password
rescue ::BCrypt::Errors::InvalidHash
  false
end