From b1eb56b3bf1dd59cb6a4364a65a6e1123b47c2b0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Joshua=20R=C3=BCsweg?= Date: Mon, 27 Aug 2018 14:28:04 +0200 Subject: [PATCH] Add support for passwordrules attribute See #2746 --- .../templates/accountManagement.tpl | 4 +- com.woltlab.wcf/templates/newPassword.tpl | 4 +- com.woltlab.wcf/templates/register.tpl | 4 +- .../lib/form/AccountManagementForm.class.php | 3 +- .../files/lib/form/NewPasswordForm.class.php | 3 +- .../files/lib/form/RegisterForm.class.php | 3 +- .../lib/util/UserRegistrationUtil.class.php | 37 +++++++++++++++++++ 7 files changed, 49 insertions(+), 9 deletions(-) diff --git a/com.woltlab.wcf/templates/accountManagement.tpl b/com.woltlab.wcf/templates/accountManagement.tpl index d1bd5e5c8a..3d900ba130 100644 --- a/com.woltlab.wcf/templates/accountManagement.tpl +++ b/com.woltlab.wcf/templates/accountManagement.tpl @@ -74,7 +74,7 @@
- + {if $errorField == 'newPassword'} @@ -88,7 +88,7 @@
- + {if $errorField == 'confirmNewPassword'} diff --git a/com.woltlab.wcf/templates/newPassword.tpl b/com.woltlab.wcf/templates/newPassword.tpl index 558f5044a4..1c771802f4 100644 --- a/com.woltlab.wcf/templates/newPassword.tpl +++ b/com.woltlab.wcf/templates/newPassword.tpl @@ -9,7 +9,7 @@
- + {if $errorField == 'newPassword'} @@ -23,7 +23,7 @@
- + {if $errorField == 'confirmNewPassword'} diff --git a/com.woltlab.wcf/templates/register.tpl b/com.woltlab.wcf/templates/register.tpl index 17424c9ed3..ed5f7883d7 100644 --- a/com.woltlab.wcf/templates/register.tpl +++ b/com.woltlab.wcf/templates/register.tpl @@ -108,7 +108,7 @@
- + {if $errorType.password|isset} {if $errorType.password == 'empty'}{lang}wcf.global.form.error.empty{/lang}{/if} @@ -124,7 +124,7 @@
- + {if $errorType.confirmPassword|isset} {if $errorType.confirmPassword == 'notEqual'}{lang}wcf.user.confirmPassword.error.notEqual{/lang}{/if} diff --git a/wcfsetup/install/files/lib/form/AccountManagementForm.class.php b/wcfsetup/install/files/lib/form/AccountManagementForm.class.php index eee2c24fee..e830496094 100644 --- a/wcfsetup/install/files/lib/form/AccountManagementForm.class.php +++ b/wcfsetup/install/files/lib/form/AccountManagementForm.class.php @@ -288,7 +288,8 @@ class AccountManagementForm extends AbstractForm { 'facebookConnect' => $this->facebookConnect, 'facebookDisconnect' => $this->facebookDisconnect, 'googleConnect' => $this->googleConnect, - 'googleDisconnect' => $this->googleDisconnect + 'googleDisconnect' => $this->googleDisconnect, + 'passwordRulesAttributeValue' => UserRegistrationUtil::getPasswordRulesAttributeValue() ]); } diff --git a/wcfsetup/install/files/lib/form/NewPasswordForm.class.php b/wcfsetup/install/files/lib/form/NewPasswordForm.class.php index 20d115932e..2509092e4a 100644 --- a/wcfsetup/install/files/lib/form/NewPasswordForm.class.php +++ b/wcfsetup/install/files/lib/form/NewPasswordForm.class.php @@ -155,7 +155,8 @@ class NewPasswordForm extends AbstractForm { WCF::getTPL()->assign([ 'user' => $this->user, 'newPassword' => $this->newPassword, - 'confirmNewPassword' => $this->confirmNewPassword + 'confirmNewPassword' => $this->confirmNewPassword, + 'passwordRulesAttributeValue' => UserRegistrationUtil::getPasswordRulesAttributeValue() ]); } } diff --git a/wcfsetup/install/files/lib/form/RegisterForm.class.php b/wcfsetup/install/files/lib/form/RegisterForm.class.php index 8a82f69085..e798ee51a1 100644 --- a/wcfsetup/install/files/lib/form/RegisterForm.class.php +++ b/wcfsetup/install/files/lib/form/RegisterForm.class.php @@ -229,7 +229,8 @@ class RegisterForm extends UserAddForm { WCF::getTPL()->assign([ 'captchaObjectType' => $this->captchaObjectType, 'isExternalAuthentication' => $this->isExternalAuthentication, - 'randomFieldNames' => $this->randomFieldNames + 'randomFieldNames' => $this->randomFieldNames, + 'passwordRulesAttributeValue' => UserRegistrationUtil::getPasswordRulesAttributeValue() ]); } diff --git a/wcfsetup/install/files/lib/util/UserRegistrationUtil.class.php b/wcfsetup/install/files/lib/util/UserRegistrationUtil.class.php index 3c9556cc84..ce51c15c94 100644 --- a/wcfsetup/install/files/lib/util/UserRegistrationUtil.class.php +++ b/wcfsetup/install/files/lib/util/UserRegistrationUtil.class.php @@ -87,6 +87,43 @@ final class UserRegistrationUtil { return true; } + /** + * Returns the `passwordrules` attribute value. + * + * @see https://developer.apple.com/password-rules/ + * @return string + */ + public static function getPasswordRulesAttributeValue() { + if (REGISTER_ENABLE_PASSWORD_SECURITY_CHECK) { + $rules = ''; + + if (REGISTER_PASSWORD_MIN_LENGTH) { + $rules .= 'minlength:'.REGISTER_PASSWORD_MIN_LENGTH.';'; + } + + if (REGISTER_PASSWORD_MUST_CONTAIN_DIGIT) { + $rules .= 'required:digit;'; + } + + if (REGISTER_PASSWORD_MUST_CONTAIN_LOWER_CASE) { + $rules .= 'required:lower;'; + } + + if (REGISTER_PASSWORD_MUST_CONTAIN_UPPER_CASE) { + $rules .= 'required:upper;'; + } + + if (REGISTER_PASSWORD_MUST_CONTAIN_SPECIAL_CHAR) { + $rules .= 'required:special;'; + } + } + else { + $rules = "minlength:8;"; + } + + return $rules; + } + /** * Generates a random activation code with the given length. * Warning: A length greater than 9 is out of integer range. -- 2.20.1