From fb9d508f62690dbbfc44150dd2831c4bc1412f83 Mon Sep 17 00:00:00 2001 From: Punyapal Shah <53343069+MrPunyapal@users.noreply.github.com> Date: Fri, 26 Jan 2024 23:50:54 +0530 Subject: [PATCH] Refactor password validation rules (#49861) --- src/Illuminate/Validation/Rules/Password.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Illuminate/Validation/Rules/Password.php b/src/Illuminate/Validation/Rules/Password.php index 588f357334cc..3fb66e9ee2bd 100644 --- a/src/Illuminate/Validation/Rules/Password.php +++ b/src/Illuminate/Validation/Rules/Password.php @@ -312,7 +312,12 @@ 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) { @@ -320,10 +325,6 @@ public function passes($attribute, $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'); }