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
29 30 31 |
# File 'lib/authenticate/model/db_password.rb', line 29 def self.required_fields(klass) [:encrypted_password] end |
Instance Method Details
#password=(new_password) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/authenticate/model/db_password.rb', line 50 def password=(new_password) @password = new_password if new_password.present? self.encrypted_password = encrypt(new_password) end end |
#password_match?(password) ⇒ Boolean
46 47 48 |
# File 'lib/authenticate/model/db_password.rb', line 46 def password_match?(password) match?(password, self.encrypted_password) end |