Class: DeviseMeteor::BCryptSHA256Hasher

Inherits:
Hasher
  • Object
show all
Defined in:
lib/devise_meteor/strategies/hasher.rb

Overview

BCryptSHA256Hasher implements a BCrypt password hasher using SHA256.

Direct Known Subclasses

BCryptHasher

Instance Attribute Summary

Attributes inherited from Hasher

#algorithm

Instance Method Summary collapse

Methods inherited from Hasher

#must_update

Constructor Details

#initializeBCryptSHA256Hasher

Returns a new instance of BCryptSHA256Hasher.



53
54
55
56
57
# File 'lib/devise_meteor/strategies/hasher.rb', line 53

def initialize
  @algorithm = :bcrypt_sha256
  @cost = 10
  @digest = OpenSSL::Digest::SHA256.new
end

Instance Method Details

#encode(password, salt) ⇒ Object



67
68
69
70
71
# File 'lib/devise_meteor/strategies/hasher.rb', line 67

def encode(password, salt)
  password = get_password_string(password)
  hash = BCrypt::Engine.hash_secret(password, salt)
  return hash
end

#get_password_string(password) ⇒ Object



63
64
65
# File 'lib/devise_meteor/strategies/hasher.rb', line 63

def get_password_string(password)
  @digest.digest(password) unless @digest.nil?
end

#saltObject



59
60
61
# File 'lib/devise_meteor/strategies/hasher.rb', line 59

def salt
  BCrypt::Engine.generate_salt(@cost)
end

#verify(password, encoded) ⇒ Object



73
74
75
76
77
78
79
# File 'lib/devise_meteor/strategies/hasher.rb', line 73

def verify(password, encoded)
  password_digest = get_password_string(password)
  hash = BCrypt::Engine.hash_secret(password_digest, encoded)
  Devise.secure_compare(encoded, hash)

  constant_time_compare(encoded, hash)
end