starfolksoftware / password-history
Add password history to your laravel applications
Fund package maintenance!
starfolksoftware
Requires
- php: ^7.4
- illuminate/contracts: ^8.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.16
- orchestra/testbench: ^6.0
- phpunit/phpunit: ^9.3
- vimeo/psalm: ^3.11
This package is auto-updated.
Last update: 2021-08-15 02:00:16 UTC
README
Add password history to your laravel applications
Installation
You can install the package via composer:
composer require starfolksoftware/password-history
You can publish and run the migrations with:
php artisan vendor:publish --provider="StarfolkSoftware\PasswordHistory\PasswordHistoryServiceProvider" --tag="migrations" php artisan migrate
You can publish the config file with:
php artisan vendor:publish --provider="StarfolkSoftware\PasswordHistory\PasswordHistoryServiceProvider" --tag="config"
This is the contents of the published config file:
[ /* * When using the "HasPasswordHistory" trait from this package, we need to know which * Eloquent model should be used to retrieve your roles. Of course, it * is often just the "PasswordHistory" model but you may use whatever you like. * * The model you want to use as a PasswordHistory model needs to implement the * `StarfolkSoftware\PasswordHistory\Contracts\PasswordHistory` contract. */ 'password_history_class' => \StarfolkSoftware\PasswordHistory\PasswordHistory::class, /** * The table name for password histories. */ 'table_name' => 'password_histories', /** * The models password column name */ 'models_password_column_name' => 'password', /** * Password change can not be the same with any password in the last * {{ password_history_check_length }} recent passwords */ 'password_history_check_length' => env('PASSWORD_HISTORY_CHECK_LENGTH', 5), /* * The user model that should be used. If null, the default user provider from your * Laravel authentication configuration will be used. */ 'user_model' => \Illuminate\Foundation\Auth\User::class, ]
Usage
Registering models
With this package, you can track password history of any model. To make your
models passwordhistorable
, add the HasPasswordHistory
to the model classes as
in the following
namespace App\Models; use Illuminate\Database\Eloquent\Model; use StarfolkSoftware\PasswordHistory\Traits\HasPasswordHistory; class User extends Model { use HasPasswordHistory; ... }
Password history is saved to the database the moment a saved
event is fired on your model. Remember that also the saved
event is fired when you first create a model.
NotInRecentPasswordHistory
validation rule
If you want to validate that a password is not in the recent password history, you
can use the NotInRecentPasswordHistory
rule as in the following snippet:
use StarfolkSoftware\PasswordHistory\Rules\NotInRecentPasswordHistory; validator(collect($model)->toArray(), [ 'password' => NotInRecentPasswordHistory::ofUser($model), ])->validate();
Testing
composer test
Psalming
./vendor/bin/psalm --show-info=true
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.