1
0
Fork 0
mirror of https://github.com/heartcombo/devise.git synced 2022-11-09 12:18:31 -05:00

Moved BCrypt logic to a encryptor

This commit is contained in:
Rodrigo Flores 2012-03-09 16:38:06 -03:00
parent b928b8b3a2
commit 9203651110
3 changed files with 12 additions and 2 deletions

View file

@ -23,6 +23,7 @@ module Devise
module Encryptors
autoload :Base, 'devise/encryptors/base'
autoload :AuthlogicSha512, 'devise/encryptors/authlogic_sha512'
autoload :BCrypt, 'devise/encryptors/bcrypt'
autoload :ClearanceSha1, 'devise/encryptors/clearance_sha1'
autoload :RestfulAuthenticationSha1, 'devise/encryptors/restful_authentication_sha1'
autoload :Sha512, 'devise/encryptors/sha512'

View file

@ -0,0 +1,9 @@
module Devise
module Encryptors
class BCrypt < Base
def self.digest(password, salt, stretches, pepper)
::BCrypt::Engine.hash_secret("#{password}#{pepper}",salt, stretches)
end
end
end
end

View file

@ -41,7 +41,7 @@ module Devise
def valid_password?(password)
return false if encrypted_password.blank?
bcrypt = ::BCrypt::Password.new(self.encrypted_password)
password = ::BCrypt::Engine.hash_secret("#{password}#{self.class.pepper}", bcrypt.salt)
password = Devise::Encryptors::BCrypt.digest(password, bcrypt.salt, self.class.stretches, self.class.pepper)
Devise.secure_compare(password, self.encrypted_password)
end
@ -107,7 +107,7 @@ module Devise
# Digests the password using bcrypt.
def password_digest(password)
::BCrypt::Password.create("#{password}#{self.class.pepper}", :cost => self.class.stretches).to_s
Devise::Encryptors::BCrypt.digest(password, ::BCrypt::Engine.generate_salt, self.class.stretches, self.class.pepper)
end
module ClassMethods