module Negroni::Encryptor

Handles password encryption and digestion

Public Class Methods

compare(klass, hashed_password, password) click to toggle source

Compare two passwords

@param klass [Class] the class for which to digest @param hashed_password [String] the hashed password to compare @param password [String] the password to compare with `hashed_password`

# File lib/negroni/encryptor.rb, line 24
def compare(klass, hashed_password, password)
  return false if hashed_password.blank?

  bcrypt   = ::BCrypt::Password.new(hashed_password)
  password = "#{password}#{klass.pepper}" if klass.pepper.present?
  password = ::BCrypt::Engine.hash_secret(password, bcrypt.salt)

  Negroni.secure_compare(password, hashed_password)
end
digest(klass, password) click to toggle source

Digest a password

@param klass [Class] the class for which to digest @param password [String] the password to digest

# File lib/negroni/encryptor.rb, line 13
def digest(klass, password)
  password = "#{password}#{klass.pepper}" if klass.pepper.present?

  ::BCrypt::Password.create(password, cost: klass.stretches).to_s
end