Module: Negroni::Encryptor
- Defined in:
- lib/negroni/encryptor.rb
Overview
Handles password encryption and digestion
Class Method Summary collapse
-
.compare(klass, hashed_password, password) ⇒ Object
Compare two passwords.
-
.digest(klass, password) ⇒ Object
Digest a password.
Class Method Details
.compare(klass, hashed_password, password) ⇒ Object
Compare two passwords
24 25 26 27 28 29 30 31 32 |
# 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) ⇒ Object
Digest a password
13 14 15 16 17 |
# 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 |