Skip to content

Commit

Permalink
Refactor password validation rules (#49861)
Browse files Browse the repository at this point in the history
  • Loading branch information
MrPunyapal authored Jan 26, 2024
1 parent abc4c98 commit fb9d508
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/Illuminate/Validation/Rules/Password.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,18 +312,19 @@ public function passes($attribute, $value)

$validator = Validator::make(
$this->data,
[$attribute => array_merge(['string', 'min:'.$this->min], $this->customRules)],
[$attribute => [
'string',
'min:'.$this->min,
...($this->max ? ['max:'.$this->max] : []),
...$this->customRules,
]],
$this->validator->customMessages,
$this->validator->customAttributes
)->after(function ($validator) use ($attribute, $value) {
if (! is_string($value)) {
return;
}

if ($this->max && mb_strlen($value) > $this->max) {
$validator->addFailure($attribute, 'max.string');
}

if ($this->mixedCase && ! preg_match('/(\p{Ll}+.*\p{Lu})|(\p{Lu}+.*\p{Ll})/u', $value)) {
$validator->addFailure($attribute, 'password.mixed');
}
Expand Down

0 comments on commit fb9d508

Please sign in to comment.