-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
[8.x] Adds password rule #36960
[8.x] Adds password rule #36960
Conversation
It would also be convenient if we could do something like: $food->ensureNotCompromisedUsing(function () => {}) then, we could use custom verifiers for it. |
@gocanto You can already provide your own implementation here:
|
Some interesting reading that may want to be considered as possible additions to the mechanics presented here: https://pages.nist.gov/800-63-3/sp800-63b.html#sec5 These suggestions are being utilised in the following package: https://github.com/langleyfoxall/laravel-nist-password-rules, which doesn't fully have Laravel 8 support, but some elements of this PR render elements of the package obsolete. |
@nunomaduro what about localization of these error messages? Should we be wrapping them in |
Besides Wouldn't it make more sense to just have a general way of chaining rules like that? |
Hello, i think you could add a rule to ensure that any character is not repeated more than X times, |
Removed Adjusted API slightly: Password::min(8)->letters()->numbers()->uncompromised(); |
36fbf84
to
ce7751c
Compare
BTW, this thread wouldn't feel complete without the obligatory XKCD comic: |
ce7751c
to
4fb92f5
Compare
$request->validate([
'name' => 'required|string|max:255',
'email' => 'required|string|email|max:255|unique:users',
// 'password' => ['required', 'confirmed', Password::min(8)->mixedCase()->uncompromised()],
'password' => Password::min(8)->required()->confirmed()->mixedCase()->uncompromised(),
$request->validate([
// Creates a normal password rule:
'password' => Password::min(8)->required()->confirmed()->mixedCase()->uncompromised(),
// Creates an authenticated guard password rule:
'password' => Password::guard('api'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me apart from a few minor things 👍
since the |
I would really like to know how to localize/create custom error messages for this. There is no info in the docs and I can't find any hint in the code. |
@diverpl You can use the For example, if your locale is {
"The :attribute must contain at least one letter.": "O campo :attribute deve conter pelo menos uma letra",
"The :attribute must contain at least one number.": "O campo :attribute deve conter pelo menos um número.",
"The :attribute must contain at least one symbol.": "O campo :attribute deve conter pelo menos um símbolo.",
"The :attribute must contain at least one uppercase and one lowercase letter.": "O campo :attribute deve conter pelo menos uma letra maiúscula e uma minúscula.",
"The given :attribute has appeared in a data leak. Please choose a different :attribute.": "O :attribute informado apareceu em um vazamento de dados. Por favor escolha uma :attribute diferente."
}
|
Take a look at the file |
thanks will check now |
Oh, and this thread wouldn't feel complete without this either: passwords.mp4 |
* Adds password rule * Typo * Fixes default compromised number * Adds "Add-Padding" header to not pwned verifier * Improves testing * work on rule * Adds uncompromised threshold * Updates docs * Removes non used import * Updates property name * Fixes docs * Updates test methods * Adds more tests * Removes mixed case test * Adds more tests * Adds tests * Update NotPwnedVerifier.php Co-authored-by: Taylor Otwell <[email protected]> Co-authored-by: Taylor Otwell <[email protected]>
Waiting for this too :) |
Hello, excuse my ignorance, but how do I customize the validation messages, that is, I want to pass them to Spanish, I know how to do it normally, but with this function I have not been able to do it, eye I do not want to touch the Password.php file. Thanks. |
@alex-gil-1981 you have to add the translation strings in the json file as mateusjunges explained here:
|
Hey, awesome feature! 😄 One question though... what is the use case for the threshold? As surely if a password appears once, it is compromised and increasing the threshold would be promoting bad practice? |
This is awesome! But awesome feature! |
@ordago Excellent thank you very much! |
@mateusjunges Thank you very much!!! This comment was very helpful~ |
I think it would be great to add an additional validation But still, thanks a lot for this new feature!! |
@lorimay21, just use the laravel-lang/publisher package. |
Is there a way to just require any 3 of the 4? |
Sending another vote for this, with the following suggestion of a magic method Password::withAny(); // OR
Password::applyAny(); e.g. 'password' => ['required', 'confirmed', Password::withAny()->min(8)->mixedCase()->letters()],
'password' => ['required', 'confirmed', Password::withAnyTwo()->min(8)->mixedCase()->letters()->numbers()],
'password' => ['required', 'confirmed', Password::withAnyThree()->min(8)->mixedCase()->letters()->symbols()], |
Hi there, |
is there a way to change the uncompromised message? Password::defaults(function () {
return Password::min(8)
->uncompromised();
});
$rules = [
'password' => ['required', Password::defaults()],
];
$messages = [
'password.uncompromised' => 'test 123',
];
$request->validate($rules, $messages); i tried that, but seems doesnt work |
Customizing the error messages of the built-in methods does not work the classic way. |
This pull request adds a new custom rule object to the framework that allows to replace existing password rules like so:
In addition, this new custom rule object contains built-in methods that you may use to ensure strong passwords:
Of course, you can always use them all combined like so:
Here is an example of the output: