[8.x] Added ability to define extra default password rules #40137
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi! This PR is only fairly simple but I think could be really useful. It adds the functionality for you to define your own custom validation rules that should be run when using the
Password::defaults()
validation rule.As far as I could see, this functionality doesn't already exist; but if it does, apologies.
To give a bit of context, I have an app that has 5 different places where users can be created and updated. At the moment, I'm using the password defaults, but also want to add a rule to make sure that every password passes a zxcvbn validation check. So my form request rules look similar to this:
By default, I always want my passwords to pass the
ZxcvbnRule
validation check, so I have this in every place where I'm usingPassword::defaults()
. So, in a way, I'm also treating that rule as a default one too.So, with my proposed change, I can do something like this to define some extra default password rules:
This means that I can then clean up my form request rules and be confident that the
ZxcvbnRule()
will always be run wherever the password defaults are used. It could look more like this:The new
->rules()
method that I've added supports rule objects and closures and they can be passed in individually or as an array like so:As far as I can see, this appears to be working. If it's something that you might consider merging, please let me know if you need any changes making 😄