Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement laravel password strength #5821

Merged
merged 3 commits into from
Jan 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,28 @@ public function boot()
);

Password::defaults(function () {
return Password::min(6);
if (! $this->app->environment('production')) {
return Password::min(6);
}
$rules = Password::min(config('app.password_min'));
$config = explode(',', config('app.password_rules'));
if (in_array('mixedCase', $config)) {
$rules = $rules->mixedCase();
}
if (in_array('letters', $config)) {
$rules = $rules->letters();
}
if (in_array('numbers', $config)) {
$rules = $rules->numbers();
}
if (in_array('symbols', $config)) {
$rules = $rules->symbols();
}
if (in_array('uncompromised', $config)) {
$rules = $rules->uncompromised();
}

return $rules;
});

if (config('database.use_utf8mb4')
Expand Down
17 changes: 17 additions & 0 deletions config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,23 @@

'cipher' => 'AES-256-CBC',

/*
|--------------------------------------------------------------------------
| Password strength
|--------------------------------------------------------------------------
|
| You can configure password strength requirements here.
| - password_min is the minimum length of the password.
| - password_rules are requirements that can be added on the password:
| mixedCase, letters, numbers, symbols, uncompromised.
| See https://laravel.com/docs/8.x/validation#validating-passwords
|
*/

'password_min' => (int) env('APP_PASSWORD_MIN', 8),

'password_rules' => env('APP_PASSWORD_RULES', 'mixedCase,letters,numbers,symbols,uncompromised'),

/*
|--------------------------------------------------------------------------
| Autoloaded Service Providers
Expand Down
7 changes: 7 additions & 0 deletions resources/lang/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"The :attribute must contain at least one uppercase and one lowercase letter.": "The :attribute must contain at least one uppercase and one lowercase letter.",
"The :attribute must contain at least one letter.": "The :attribute must contain at least one letter.",
"The :attribute must contain at least one symbol.": "The :attribute must contain at least one symbol.",
"The :attribute must contain at least one number.": "The :attribute must contain at least one number.",
"The given :attribute has appeared in a data leak. Please choose a different :attribute.": "The given :attribute has appeared in a data leak. Please choose a different :attribute."
}
7 changes: 7 additions & 0 deletions resources/lang/fr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"The :attribute must contain at least one uppercase and one lowercase letter.": "Le champ :attribute doit avoir au moins une lettre majuscule et une lettre minuscule.",
"The :attribute must contain at least one letter.": "Le champ :attribute doit avoir au moins une lettre.",
"The :attribute must contain at least one symbol.": "Le champ :attribute doit avoir au moins un symbole.",
"The :attribute must contain at least one number.": "Le champ :attribute doit avoir au moins un numéro.",
"The given :attribute has appeared in a data leak. Please choose a different :attribute.": "La valeur du champ :attribute est apparue dans une fuite de données. Veuillez choisir une valeur différente."
}