mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
Speed up bcrypt handling
This commit is contained in:
parent
a8d2dce563
commit
4600b4ab22
1 changed files with 8 additions and 5 deletions
|
@ -1,13 +1,16 @@
|
|||
module Devise
|
||||
module Encryptors
|
||||
# Encryptor for BCrypt. It ignores the values given for salt,
|
||||
# as it is repsonsible for managing its own salt.
|
||||
class BCrypt < Base
|
||||
def self.digest(password, stretches, salt, pepper)
|
||||
::BCrypt::Engine.hash_secret("#{password}#{pepper}",salt, stretches)
|
||||
def self.digest(password, stretches, _salt, pepper)
|
||||
::BCrypt::Password.create("#{password}#{pepper}", :cost => stretches).to_s
|
||||
end
|
||||
|
||||
def self.compare(encrypted_password, password, stretches, salt, pepper)
|
||||
salt = ::BCrypt::Password.new(encrypted_password).salt
|
||||
Devise.secure_compare(encrypted_password, digest(password, stretches, salt, pepper))
|
||||
def self.compare(encrypted_password, password, _stretches, _salt, pepper)
|
||||
bcrypt = ::BCrypt::Password.new(encrypted_password)
|
||||
password = ::BCrypt::Engine.hash_secret("#{password}#{pepper}", bcrypt.salt)
|
||||
Devise.secure_compare(password, encrypted_password)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue