module Clearance::PasswordStrategies::Blowfish
Public Instance Methods
authenticated?(password)
click to toggle source
# File lib/clearance/password_strategies/deprecated/blowfish.rb, line 9 def authenticated?(password) encrypted_password == encrypt(password) end
password=(new_password)
click to toggle source
# File lib/clearance/password_strategies/deprecated/blowfish.rb, line 13 def password=(new_password) @password = new_password initialize_salt_if_necessary if new_password.present? self.encrypted_password = encrypt(new_password) end end
Protected Instance Methods
encrypt(string)
click to toggle source
# File lib/clearance/password_strategies/deprecated/blowfish.rb, line 24 def encrypt(string) generate_hash("--#{salt}--#{string}--") end
generate_hash(string)
click to toggle source
# File lib/clearance/password_strategies/deprecated/blowfish.rb, line 28 def generate_hash(string) cipher = OpenSSL::Cipher::Cipher.new("bf-cbc").encrypt cipher.key = Digest::SHA256.digest(salt)[0..15] hash = cipher.update(string) << cipher.final Base64.encode64(hash).encode("utf-8") end
generate_salt()
click to toggle source
# File lib/clearance/password_strategies/deprecated/blowfish.rb, line 41 def generate_salt Base64.encode64(SecureRandom.hex(20)).encode("utf-8") end
initialize_salt_if_necessary()
click to toggle source
# File lib/clearance/password_strategies/deprecated/blowfish.rb, line 35 def initialize_salt_if_necessary if salt.blank? self.salt = generate_salt end end