module Authenticate::Model::DbPassword

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:

Columns

Methods

The following methods are added to your user model:

Validations

Public Class Methods

required_fields(_klass) click to toggle source
# File lib/authenticate/model/db_password.rb, line 28
def self.required_fields(_klass)
  [:encrypted_password]
end

Public Instance Methods

password=(new_password) click to toggle source
# 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) click to toggle source
# File lib/authenticate/model/db_password.rb, line 42
def password_match?(password)
  match?(password, encrypted_password)
end

Private Instance Methods

skip_password_validation?() click to toggle source

If we already have an encrypted password and it's not changing, skip the validation.

# File lib/authenticate/model/db_password.rb, line 66
def skip_password_validation?
  encrypted_password.present? && !encrypted_password_changed?
end