devlop / secure-password-rule
Extendable SecurePassword rule for Laravel
Requires
- php: ^7.4|^8.0
- laravel/framework: ^7.0|^8.0
- roave/dont: ^1.1
This package is auto-updated.
Last update: 2024-12-05 16:31:26 UTC
README
SecurePasswordRule
An extendable password validation rule for Laravel to make it easy to have the same password requirements across the whole system.
The initial settings are very permissive and pretty much only checks the length of the password, see Configuration
for how to
change it for your needs.
Installation
composer require devlop/secure-password-rule
Usage
Add it to the rules
of a FormRequest
namespace App\Http\Requests;
use Devlop\SecurePasswordRule\SecurePasswordRule;
use Illuminate\Foundation\Http\FormRequest;
class ChangePasswordRequest extends FormRequest
{
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'new_password' => [
'required',
'string',
new SecurePasswordRule,
],
];
}
}
Configuration
The class is open for extension and does not accept any arguments when instantiating since that would open the possibility of ending up with different password requirements in different parts of your system.
The recommended way is to create your own sub class of SecurePasswordRule and change the parameters you wish to change, and then reference that sub class instead in your FormRequests.
namespace App\Rules;
use Devlop\SecurePasswordRule\SecurePasswordRule as BaseSecurePasswordRule;
class SecurePasswordRule extends BaseSecurePasswordRule
{
/**
* Require the use of X special characters
*/
protected int $requireSpecial = 10;
}