diff --git a/lang/en/lang.php b/lang/en/lang.php index 3870796e..331a9326 100644 --- a/lang/en/lang.php +++ b/lang/en/lang.php @@ -74,7 +74,7 @@ 'activation_tab' => 'Activation', 'signin_tab' => 'Sign in', 'registration_tab' => 'Registration', - 'password_policy_tab' => 'Password policy', + 'password_policy_tab' => 'Password Policy', 'profile_tab' => 'Profile', 'notifications_tab' => 'Notifications', 'allow_registration' => 'Allow user registration', @@ -104,8 +104,6 @@ 'remember_ask' => 'Ask the user on login', 'min_password_length' => 'Min password length', 'min_password_length_comment' => 'Password length required for users', - 'password_policy_hint_warning' => 'October CMS v3 and later', - 'password_policy_hint_warning_comment' => 'The password policies below will only work on October CMS v3 and later', 'require_mixed_case' => 'Require mixed case', 'require_mixed_case_comment' => 'Require uppercase and lowercase letters', 'require_number' => 'Require number', diff --git a/models/User.php b/models/User.php index e20b2724..29d51253 100644 --- a/models/User.php +++ b/models/User.php @@ -8,6 +8,7 @@ use Carbon\Carbon; use October\Rain\Auth\Models\User as UserBase; use RainLab\User\Models\Settings as UserSettings; +use Illuminate\Validation\Rules\Password as PasswordRule; use October\Rain\Auth\AuthException; class User extends UserBase @@ -274,31 +275,25 @@ public function beforeValidate() * Apply rules Settings */ $minPasswordLength = Settings::get('min_password_length', static::getMinPasswordLength()); - if (class_exists('\Illuminate\Validation\Rules\Password')) { - $passwordRule = \Illuminate\Validation\Rules\Password::min($minPasswordLength); - if (Settings::get('require_mixed_case')) { - $passwordRule->mixedCase(); - } - - if (Settings::get('require_uncompromised')) { - $passwordRule->uncompromised(); - } - - if (Settings::get('require_number')) { - $passwordRule->numbers(); - } + $passwordRule = PasswordRule::min($minPasswordLength); + if (Settings::get('require_mixed_case')) { + $passwordRule->mixedCase(); + } - if (Settings::get('require_symbol')) { - $passwordRule->symbols(); - } + if (Settings::get('require_uncompromised')) { + $passwordRule->uncompromised(); + } - $this->addValidationRule('password', $passwordRule); - $this->addValidationRule('password_confirmation', $passwordRule); + if (Settings::get('require_number')) { + $passwordRule->numbers(); } - else { - $this->rules['password'] = "required:create|between:$minPasswordLength,255|confirmed"; - $this->rules['password_confirmation'] = "required_with:password|between:$minPasswordLength,255"; + + if (Settings::get('require_symbol')) { + $passwordRule->symbols(); } + + $this->addValidationRule('password', $passwordRule); + $this->addValidationRule('password_confirmation', $passwordRule); } /** diff --git a/models/settings/fields.yaml b/models/settings/fields.yaml index 6985b8d9..15bfc323 100644 --- a/models/settings/fields.yaml +++ b/models/settings/fields.yaml @@ -76,13 +76,6 @@ tabs: comment: rainlab.user::lang.settings.min_password_length_comment tab: rainlab.user::lang.settings.password_policy_tab - _october_cms_3: - type: hint - mode: warning - label: rainlab.user::lang.settings.password_policy_hint_warning - comment: rainlab.user::lang.settings.password_policy_hint_warning_comment - tab: rainlab.user::lang.settings.password_policy_tab - # Require Mixed Case require_mixed_case: span: left