Module: CASServer::Authenticators::SQLEncrypted::EncryptedPassword
- Defined in:
- lib/casserver/authenticators/sql_encrypted.rb
Overview
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.
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.included(mod) ⇒ Object
52 53 54 55 |
# File 'lib/casserver/authenticators/sql_encrypted.rb', line 52 def self.included(mod) raise "#{self} should be inclued in an ActiveRecord class!" unless mod.respond_to?(:before_save) mod.before_save :generate_encryption_salt end |
Instance Method Details
#encrypt(str) ⇒ Object
57 58 59 60 |
# File 'lib/casserver/authenticators/sql_encrypted.rb', line 57 def encrypt(str) generate_encryption_salt unless encryption_salt Digest::SHA256.hexdigest("#{encryption_salt}::#{str}") end |
#generate_encryption_salt ⇒ Object
66 67 68 69 |
# File 'lib/casserver/authenticators/sql_encrypted.rb', line 66 def generate_encryption_salt self.encryption_salt = Digest::SHA1.hexdigest(Crypt::ISAAC.new.rand(2**31).to_s) unless encryption_salt end |
#password=(password) ⇒ Object
62 63 64 |
# File 'lib/casserver/authenticators/sql_encrypted.rb', line 62 def password=(password) self[:encrypted_password] = encrypt(password) end |