Module | CASServer::Authenticators::SQLEncrypted::EncryptedPassword |
In: |
lib/casserver/authenticators/sql_encrypted.rb
|
Include this module into your application‘s user model.
Your model must have an ‘encrypted_password’ column where the password will be stored, and an ‘encryption_salt’ column that will be populated with a random string before the user record is first created.
# File lib/casserver/authenticators/sql_encrypted.rb, line 21 21: def self.included(mod) 22: raise "#{self} should be inclued in an ActiveRecord class!" unless mod.respond_to?(:before_save) 23: mod.before_save :generate_encryption_salt 24: end
# File lib/casserver/authenticators/sql_encrypted.rb, line 26 26: def encrypt(str) 27: generate_encryption_salt unless encryption_salt 28: Digest::SHA256.hexdigest("#{encryption_salt}::#{str}") 29: end
# File lib/casserver/authenticators/sql_encrypted.rb, line 35 35: def generate_encryption_salt 36: self.encryption_salt = Digest::SHA1.hexdigest(Crypt::ISAAC.new.rand(2**31).to_s) unless 37: encryption_salt 38: end