Skip to content

muhammedsaidckr/password-policy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Laravel Password Policy

This package ensures that the last used (n) password/s are not entered.

Requirements

Laravel Fortify or Jetstream has to be installed.

Installation

composer require ddtech/laravel-password-policy
php artisan vendor:publish --tag=migrations
php artisan migrate

Usage

Add PasswordRecords Traits to User Model

use PasswordRecords;

You need to change Fortify, ResetUserPassword's reset function

Validator::make($input, [
  'password' => $this->passwordRules(),
])->validate();
Validator::make($input, [
    'password' => $this->passwordRules(),
])->after(function ($validator) use ($user, $input) {
    $user->oldPasswordRules($validator, $user, $input, 3);
})->validate();

$user->triggerPasswordRecord($user->password);

You need to change Fortify, UpdateUserPassword's update function

Validator::make($input, [
    'current_password' => ['required', 'string'],
    'password' => $this->passwordRules(),
])->after(function ($validator) use ($user, $input) {
    if (! isset($input['current_password']) || ! Hash::check($input['current_password'], $user->password)) {
        $validator->errors()->add('current_password', __('The provided password does not match your current password.'));
    }
})->validateWithBag('updatePassword');
Validator::make($input, [
    'current_password' => ['required', 'string'],
    'password' => $this->passwordRules(),
])->after(function ($validator) use ($user, $input) {
    if (! isset($input['current_password']) || ! Hash::check($input['current_password'], $user->password)) {
        $validator->errors()->add('current_password', __('The provided password does not match your current password.'));
    }
    $user->oldPasswordRules($validator, $user, $input, 3);
})->validateWithBag('updatePassword');

$user->triggerPasswordRecord($user->password);

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages