dilneiss / laravel-nist-password-rules
🔒 Provides Laravel validation rules that follow the password related recommendations found in NIST Special Publication 800-63B.
Requires
- php: >=7.2
- dilneiss/laravel-password-exposed-validation-rule: ^3.0
- laravel/framework: ^5.5||^6.0||^7.0||^8.0||^9.0||^10.0||^11.0
Requires (Dev)
- fakerphp/faker: ^1.14.1|^1.9.1
- orchestra/testbench: ^5.17.1|^7.0
- php-coveralls/php-coveralls: ^2.0
This package is auto-updated.
Last update: 2024-10-29 13:26:36 UTC
README
This package provides Laravel validation rules that follow the password related recommendations found in NIST Special Publication 800-63B section 5.
Laravel NIST Password Rules implements the following recommendations.
It also provides methods to return validation rules arrays for various scenarios, such as register, login, and password changes. These arrays can be passed directly into the Laravel validator.
Installation
Laravel NIST Password Rules can be easily installed using Composer. Just run the following command from the root of your project.
composer require langleyfoxall/laravel-nist-password-rules
If you have never used the Composer dependency manager before, head to the Composer website for more information on how to get started.
Optionally, you may publish the package's translation files with the following Artisan command.
php artisan vendor:publish --provider="LangleyFoxall\LaravelNISTPasswordRules\ServiceProvider"
Usage
To use the Laravel NIST Password Rules in your project, first use
the
PasswordRules
class, then call the appropriate static methods to return
an array of appropriate validation rules. There are methods available for
the following scenerios.
- Register
- Change password, with old password
- Change password, without old password
- Optionally change password, with old password
- Optionally change password, without old password
- Login
See the code below for example usage syntax.
use LangleyFoxall\LaravelNISTPasswordRules\PasswordRules; // Register $this->validate($request, [ 'email' => 'required', 'password' => PasswordRules::register($request->email), ]); // Register, without requiring password confirmation $this->validate($request, [ 'email' => 'required', 'password' => PasswordRules::register($request->email, false), ]); // Change password, with old password $this->validate($request, [ 'old_password' => 'required', 'password' => PasswordRules::changePassword($request->email, 'old_password'), ]); // Change password, without old password $this->validate($request, [ 'password' => PasswordRules::changePassword($request->email), ]); // Optionally change password, with old password $this->validate($request, [ 'old_password' => 'required', 'password' => PasswordRules::optionallyChangePassword($request->email, 'old_password'), ]); // Optionally change password, without old password $this->validate($request, [ 'password' => PasswordRules::optionallyChangePassword($request->email), ]); // Login $this->validate($request, [ 'email' => 'required', 'password' => PasswordRules::login(), ]);
The optionallyChangePassword
method supplies validation rules that are
appropriate for forms in which the password can be optionally changed if
filled in.