Module: Maquina::RetainPasswords

Extended by:
ActiveSupport::Concern
Included in:
User
Defined in:
app/models/concerns/maquina/retain_passwords.rb

Overview

A concern that implements password history and reuse prevention.

Usage

Include this concern in models that need password history tracking:

class User < ApplicationRecord
  include Maquina::RetainPasswords
end

Configuration

Password retention behavior is controlled by:

  • Maquina.configuration.password_retain_count

    Number of previous passwords to retain

Callbacks

When included, automatically adds:

  • Validation to prevent password reuse

  • After create: Stores initial password in history

  • After update: Stores new password in history when password changes

Validations

  • password

    Must not match any previously used passwords within retention limit

Example

class User < ApplicationRecord
  include Maquina::RetainPasswords
  has_secure_password
end

user.update(password: 'old_password') # Stored in history
user.update(password: 'old_password') # Validation error: password already used