Module: Devise::Encryptor

Defined in:
lib/devise/encryptor.rb

Class Method Summary collapse

Class Method Details

.compare(klass, hashed_password, password) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/devise/encryptor.rb', line 12

def self.compare(klass, hashed_password, password)
  return false if hashed_password.blank?
  bcrypt   = ::BCrypt::Password.new(hashed_password)
  if klass.pepper.present?
    password = "#{password}#{klass.pepper}"
  end
  password = ::BCrypt::Engine.hash_secret(password, bcrypt.salt)
  Devise.secure_compare(password, hashed_password)
end

.digest(klass, password) ⇒ Object



5
6
7
8
9
10
# File 'lib/devise/encryptor.rb', line 5

def self.digest(klass, password)
  if klass.pepper.present?
    password = "#{password}#{klass.pepper}"
  end
  ::BCrypt::Password.create(password, cost: klass.stretches).to_s
end