mei-labs/filament-renew-password

Package for manage recurring renew password

v2.1.0 2024-03-23 14:22 UTC

This package is auto-updated.

Last update: 2024-04-23 14:32:17 UTC


README

The Filament Renew Password Plugin enhances Filament by prompting users to renew their passwords based on specified criteria.

Screenshot

Installation

  1. Install the package using the composer command:
composer require mei-labs/fi-renew-password
  1. Publish the associated vendor files and run the migration, which adds a new column last_renew_password_at to the users table.
php artisan vendor:publish
php artisan migrate

Alternatively, if you don't want to publish the migrations or already have a column in your database for such case, you can skip this step and customize the column name by using any of the configuration methods described in the Configuration section below.

  1. Register the plugin in your panel provider:
use MeiLABS\Filament\RenewPassword\RenewPasswordPlugin;

public function panel(Panel $panel): Panel
{
    return $panel
       ->plugin(new RenewPasswordPlugin());
}

Configuration

Filament Renew Password Plugin is designed to work out of the box with minimal configuration. However, you can customize the plugin by publishing the configuration file, changing the environment variables or using the plugin object to override the default settings.

Via Plugin Configuration

// app/Providers/Filament/YourPanelServiceProvider.php

RenewPasswordPlugin::make()
    ->timestampColumn('password_changed_at')
    ->passwordExpiresIn(days: 30)

Via Environment Variables

// .env

FILAMENT_RENEW_PASSWORD_DAYS_PERIOD=30
FILAMENT_RENEW_PASSWORD_TIMESTAMP_COLUMN=last_renew_password_at

Via Configuration File

// config/filament-renew-password.php

return [
    'timestamp_column' => 'password_changed_at',
    'password_expires_in' => 30,
];

Any of the above methods will work. The plugin will use the configuration in the following order of priority: Plugin Configuration, Environment Variables, Configuration File.

Usage

  1. Implement the RenewPasswordContract on your Authentication Model (User) and define the criteria for prompting password renewal in the needRenewPassword function.

Example for a 90-day renewal period:

class User extends Authenticatable implements RenewPasswordContract
{
    ... 
    
    public function needRenewPassword(): bool
    {
        return Carbon::parse($this->last_renew_password_at ?? $this->created_at)->addDays(90) < now();
    }
}

Alternatively, you can use the RenewPassword trait on your Authentication Model (User). By default, the trait uses the configured column and a 90-day renewal period. You can customize the column name and renewal period by configuring the plugin.

class User extends Authenticatable implements RenewPasswordContract
{
    use RenewPassword;
}