Module: EncryptedPassword
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/app/models/concerns/encrypted_password.rb
Overview
Hold onto a secure password supporting both storage (setting) and retrieval ()getting) the password.
The security will lie in the key that is offered by the object. By default it will be the ID of the object however it should really use be combined with some other known value like account.id or something
Class Method Summary collapse
-
.included(base) ⇒ Object
Base class extension.
Instance Method Summary collapse
-
#password ⇒ Object
Retrieve the password.
-
#password=(pass) ⇒ Object
Set the password.
Class Method Details
.included(base) ⇒ Object
Base class extension
12 13 14 15 16 17 18 19 20 |
# File 'lib/app/models/concerns/encrypted_password.rb', line 12 def self.included(base) base.class_eval do include CipherAble # # Fields # field :encrypted_password, type: String end end |
Instance Method Details
#password ⇒ Object
Retrieve the password
25 26 27 28 29 30 |
# File 'lib/app/models/concerns/encrypted_password.rb', line 25 def password encrypted_password.present? ? cipher.decrypt_and_verify(encrypted_password) : '' rescue StandardError => error App47Logger.log_warn("Unable to retrieve password for #{inspect}", error) nil end |
#password=(pass) ⇒ Object
Set the password
35 36 37 38 39 40 |
# File 'lib/app/models/concerns/encrypted_password.rb', line 35 def password=(pass) set encrypted_password: cipher.encrypt_and_sign(pass) rescue StandardError => error App47Logger.log_error("Unable to store password for #{inspect}", error) nil end |