Skip to content

Commit

Permalink
Merge pull request #509 from rainlab/next
Browse files Browse the repository at this point in the history
[2.x] Exclusivity with OC v3
  • Loading branch information
daftspunk authored Feb 16, 2023
2 parents 837c81f + 56931b3 commit 78c1592
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 31 deletions.
4 changes: 1 addition & 3 deletions lang/en/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
37 changes: 16 additions & 21 deletions models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}

/**
Expand Down
7 changes: 0 additions & 7 deletions models/settings/fields.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 78c1592

Please sign in to comment.