Add zxcvbn to RegisterForm
authorTim Düsterhus <duesterhus@woltlab.com>
Thu, 16 Jul 2020 12:41:25 +0000 (14:41 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Thu, 16 Jul 2020 13:16:58 +0000 (15:16 +0200)
com.woltlab.wcf/templates/register.tpl
wcfsetup/install/files/lib/data/user/UserRegistrationAction.class.php
wcfsetup/install/files/lib/form/RegisterForm.class.php

index 7946618a2ca3d8e0508e54fc3bacd10910c987f4..df27a72a6862df059cc26cbe10b93b5ef0f43206 100644 (file)
                        minlength: {@REGISTER_USERNAME_MIN_LENGTH},
                        maxlength: {@REGISTER_USERNAME_MAX_LENGTH}
                });
+               
+               require(['WoltLabSuite/Core/Ui/User/PasswordStrength'], function (PasswordStrength) {
+                       new PasswordStrength(elById('{@$randomFieldNames[password]}'), {
+                               relatedInputs: [
+                                       elById('{@$randomFieldNames[username]}'),
+                                       elById('{@$randomFieldNames[email]}')
+                               ]
+                       });
+               })
        });
 </script>
 
index 0a44b0e8a3e174c507e0071c8004d0ca8bcbc1ff..f520ed62cd0ca4cb83e6124fb78411c427119250 100644 (file)
@@ -89,18 +89,9 @@ class UserRegistrationAction extends UserAction {
        }
        
        /**
-        * Validates given password.
-        * 
-        * @return      array
+        * @deprecated  5.3 - Always returns isValid = true.
         */
        public function validatePassword() {
-               if (!UserRegistrationUtil::isSecurePassword($this->parameters['password'])) {
-                       return [
-                               'isValid' => false,
-                               'error' => 'notSecure'
-                       ];
-               }
-               
                return [
                        'isValid' => true
                ];
index 26a3f0ab24a5bea345d43ed8422453219b8978cf..8880750bf0ff42b80029c871d69c59280892b57e 100644 (file)
@@ -99,6 +99,11 @@ class RegisterForm extends UserAddForm {
         */
        public static $minRegistrationTime = 10;
        
+       /**
+        * @var mixed[]
+        */
+       public $passwordStrengthVerdict = [];
+       
        /**
         * @inheritDoc
         */
@@ -145,6 +150,14 @@ class RegisterForm extends UserAddForm {
                if (isset($_POST[$this->randomFieldNames['email']])) $this->email = StringUtil::trim($_POST[$this->randomFieldNames['email']]);
                if (isset($_POST[$this->randomFieldNames['confirmEmail']])) $this->confirmEmail = StringUtil::trim($_POST[$this->randomFieldNames['confirmEmail']]);
                if (isset($_POST[$this->randomFieldNames['password']])) $this->password = $_POST[$this->randomFieldNames['password']];
+               if (isset($_POST[$this->randomFieldNames['password'].'_passwordStrengthVerdict'])) {
+                       try {
+                               $this->passwordStrengthVerdict = JSON::decode($_POST[$this->randomFieldNames['password'].'_passwordStrengthVerdict']);
+                       }
+                       catch (SystemException $e) {
+                               // ignore
+                       }
+               }
                if (isset($_POST[$this->randomFieldNames['confirmPassword']])) $this->confirmPassword = $_POST[$this->randomFieldNames['confirmPassword']];
                
                $this->groupIDs = [];
@@ -295,7 +308,7 @@ class RegisterForm extends UserAddForm {
                        parent::validatePassword($password, $confirmPassword);
                        
                        // check security of the given password
-                       if (!UserRegistrationUtil::isSecurePassword($password)) {
+                       if (($this->passwordStrengthVerdict['score'] ?? 4) < PASSWORD_MIN_SCORE) {
                                throw new UserInputException('password', 'notSecure');
                        }
                }