Module: Authenticate::Model::DbPassword
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/authenticate/model/db_password.rb
Overview
Encrypts and stores a password in the database to validate the authenticity of a user while logging in.
Authenticate can plug in any crypto provider, but currently only features BCrypt.
A crypto provider must provide:
-
encrypt(secret) - encrypt the secret, @return [String]
-
match?(secret, encrypted) - does the secret match the encrypted? @return [Boolean]
Columns
-
encrypted_password - the user’s password, encrypted
Methods
The following methods are added to your user model:
-
password=(new_password) - encrypt and set the user password
-
password_match?(password) - checks to see if the user’s password matches the given password
Validations
-
:password validation, requiring the password is set unless we’re skipping due to a password change
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.required_fields(_klass) ⇒ Object
28 29 30 |
# File 'lib/authenticate/model/db_password.rb', line 28 def self.required_fields(_klass) [:encrypted_password] end |
Instance Method Details
#password=(new_password) ⇒ Object
46 47 48 49 |
# File 'lib/authenticate/model/db_password.rb', line 46 def password=(new_password) @password = new_password self.encrypted_password = encrypt(new_password) unless new_password.nil? end |
#password_match?(password) ⇒ Boolean
42 43 44 |
# File 'lib/authenticate/model/db_password.rb', line 42 def password_match?(password) match?(password, encrypted_password) end |