Sha256: 466231da7354f50c3400ec0ea050872a55f844732cebfddf61ab3f85725e2564
Contents?: true
Size: 918 Bytes
Versions: 14
Compression:
Stored size: 918 Bytes
Contents
require 'openssl' module Clearance module PasswordStrategies module Blowfish def authenticated?(password) encrypted_password == encrypt(password) end def password=(new_password) @password = new_password initialize_salt_if_necessary if new_password.present? self.encrypted_password = encrypt(new_password) end end protected def encrypt(string) generate_hash("--#{salt}--#{string}--") end def generate_hash(string) cipher = OpenSSL::Cipher::Cipher.new('bf-cbc').encrypt cipher.key = Digest::SHA256.digest(salt) cipher.update(string) << cipher.final end def initialize_salt_if_necessary if salt.blank? self.salt = generate_salt end end def generate_salt SecureRandom.hex(20).encode('UTF-8') end end end end
Version data entries
14 entries across 14 versions & 1 rubygems