Răsfoiți Sursa

fix: 商家后台注册/找回密码增加弱密码检测

周玉环 1 săptămână în urmă
părinte
comite
2ca091955c

+ 34 - 69
xinkeaboard-seller/src/pages/User/Login.js

@@ -11,7 +11,8 @@ import {
   sldSvgIcon,
   saveSettleData,
   sldCheckMobile,
-  getSldImgSet,sldComLanguage,mobile_reg
+  getSldImgSet,sldComLanguage,mobile_reg,
+  unifyValidatePassword
 } from '@/utils/utils';
 import router from 'umi/router';
 
@@ -323,78 +324,42 @@ export default class LoginPage extends Component {
   };
 
   checkPassword = (rule, value, callback) => {
-    if(!value){
-      callback('');
-      this.setState({
-        is_show_pwd_err: true,
-        pwd_error_info: `${sldComLanguage('请输入密码')}`,
-      });
-      return
-    }
-    if (value.length < 6 || value.length > 20) {
+    const res = unifyValidatePassword(value);
+    if (!res.ok) {
       callback('');
       this.setState({
         is_show_pwd_err: true,
-        pwd_error_info: `${sldComLanguage('请输入6~20位密码')}`,
-      });
-    } else {
-      if (/[\u4E00-\u9FA5]/g.test(value)) {
-        callback('');
-        this.setState({
-          is_show_pwd_err: true,
-          pwd_error_info: `${sldComLanguage('密码不可以有中文')}`,
-        });
-      }else if(!(/^\S*$/.test(value))){
-        callback('');
-        this.setState({
-          is_show_pwd_err: true,
-          pwd_error_info: `${sldComLanguage('密码中不可以有空格')}`,
-        });
-      }
-      callback();
-      this.setState({
-        is_show_pwd_err: false,
-        pwd_error_info: `${sldComLanguage('')}`,
+        pwd_error_info: `${sldComLanguage(res.reasons[0])}`,
       });
+      return;
     }
+
+    callback();
+    this.setState({
+      is_show_pwd_err: false,
+      pwd_error_info: `${sldComLanguage('')}`,
+    });
   };
 
   //确认密码
   checkConfirmPassword = (rule, value, callback) => {
-    if(!value){
+    const pwd = this.props.form.getFieldValue('vendorPassword');
+    console.log(pwd, 'pwd')
+    if (value !== pwd) {
       callback('');
       this.setState({
         is_show_comfirepwd_err: true,
-        comfirepwd_error_info: `${sldComLanguage('请输入确认密码')}`,
-      });
-      return
-    }
-    if (value.length < 6 || value.length > 20) {
-      callback('');
-      this.setState({
-        is_show_comfirepwd_err: true,
-        comfirepwd_error_info: `${sldComLanguage('请输入6~20位密码')}`,
-      });
-    } else {
-      if (/[\u4E00-\u9FA5]/g.test(value)) {
-        callback('');
-        this.setState({
-          is_show_comfirepwd_err: true,
-          comfirepwd_error_info: `${sldComLanguage('密码不可以有中文')}`,
-        });
-      }else if(!(/^\S*$/.test(value))){
-        callback('');
-        this.setState({
-          is_show_comfirepwd_err: true,
-          comfirepwd_error_info: `${sldComLanguage('密码中不可以有空格')}`,
-        });
-      }
-      callback();
-      this.setState({
-        is_show_comfirepwd_err: false,
-        comfirepwd_error_info: `${sldComLanguage('')}`,
+        comfirepwd_error_info: `${sldComLanguage('两次输入的密码不一致')}`,
       });
+
+      return;
     }
+
+    callback();
+    this.setState({
+      is_show_comfirepwd_err: false,
+      comfirepwd_error_info: `${sldComLanguage('')}`,
+    });
   };
 
   //验证手机
@@ -889,7 +854,7 @@ export default class LoginPage extends Component {
               {modal_type == 'register' && this.state.is_show_account_err &&
               <div className={styles.register_error}>
                 {sldSvgIcon('#ef1216', 16, 16, 'cuowutishi')}
-                {this.state.account_error_info}~
+                {this.state.account_error_info}
               </div>
               }
 
@@ -916,7 +881,7 @@ export default class LoginPage extends Component {
               {this.state.is_show_phone_err &&
               <div className={styles.register_error}>
                 {sldSvgIcon('#ef1216', 16, 16, 'cuowutishi')}
-                {this.state.phone_error_info}~
+                {this.state.phone_error_info}
               </div>
               }
 
@@ -946,7 +911,7 @@ export default class LoginPage extends Component {
               {this.state.is_show_code_err &&
               <div className={styles.register_error}>
                 {sldSvgIcon('#ef1216', 16, 16, 'cuowutishi')}
-                {this.state.code_error_info}~
+                {this.state.code_error_info}
               </div>
               }
 
@@ -978,7 +943,7 @@ export default class LoginPage extends Component {
               {this.state.is_show_phonecode_err &&
               <div className={styles.register_error}>
                 {sldSvgIcon('#ef1216', 16, 16, 'cuowutishi')}
-                {this.state.phonecode_error_info}~
+                {this.state.phonecode_error_info}
               </div>
               }
 
@@ -1007,7 +972,7 @@ export default class LoginPage extends Component {
               {this.state.is_show_email_err &&
               <div className={styles.register_error}>
                 {sldSvgIcon('#ef1216', 16, 16, 'cuowutishi')}
-                {this.state.email_error_info}~
+                {this.state.email_error_info}
               </div>
               }
 
@@ -1036,7 +1001,7 @@ export default class LoginPage extends Component {
               {modal_type == 'forgetPwd' && this.state.is_show_account_err &&
                 <div className={styles.register_error}>
               {sldSvgIcon('#ef1216', 16, 16, 'cuowutishi')}
-              {this.state.account_error_info}~
+              {this.state.account_error_info}
                 </div>
               }
 
@@ -1053,7 +1018,7 @@ export default class LoginPage extends Component {
                   <Input.Password
                     maxLength={20}
                     onChange={this.handleChangeRegister}
-                    placeholder={sldComLanguage('请设置6~20位字母、数字或符号组成的密码')}
+                    placeholder={sldComLanguage('请输入密码')}
                     prefix={<p className={styles.user_name}><span
                       className={styles.must}>*</span>{modal_type == 'register' ? `${sldComLanguage('设置密码')}` : `${sldComLanguage('新密码')}`}</p>}
                   />,
@@ -1063,7 +1028,7 @@ export default class LoginPage extends Component {
               {this.state.is_show_pwd_err &&
               <div className={styles.register_error}>
                 {sldSvgIcon('#ef1216', 16, 16, 'cuowutishi')}
-                {this.state.pwd_error_info}~
+                {this.state.pwd_error_info}
               </div>
               }
 
@@ -1095,7 +1060,7 @@ export default class LoginPage extends Component {
               {this.state.is_show_comfirepwd_err &&
               <div className={styles.register_error}>
                 {sldSvgIcon('#ef1216', 16, 16, 'cuowutishi')}
-                {this.state.comfirepwd_error_info}~
+                {this.state.comfirepwd_error_info}
               </div>
               }
 
@@ -1104,7 +1069,7 @@ export default class LoginPage extends Component {
               {is_show_registe_err &&
               <div className={styles.register_error}>
                 {sldSvgIcon('#ef1216', 16, 16, 'cuowutishi')}
-                {register_error_info}~
+                {register_error_info}
               </div>
               }
 

+ 50 - 0
xinkeaboard-seller/src/utils/utils.js

@@ -1886,3 +1886,53 @@ export const businessStateEnum = {
   3: '经营中',
   4: '暂停经营',
 }
+
+const SPECIAL_CHAR_CLASS = /[~!@#$%^&*()_+`\-={}\[\]\|:;\"'<,>.?\/]/;
+const DIGIT_CLASS = /[0-9]/;
+const LOWER_CLASS = /[a-z]/;
+const UPPER_CLASS = /[A-Z]/;
+// 检查所有空格字符(半角/全角)
+// - \s 会捕获常见的空格、制表符、换行符等
+// - \u3000 是全角空格
+const SPACE_REG = /[\s\u3000]/;
+
+
+// 如果想限制“只能使用上述字符(不允许空格、中文等)”,可启用下行:
+// const ALLOWED_ALL = /^[0-9A-Za-z~!@#$%^&*()_+`\-={}\[\]\|:;\"'<,>.?\/]+$/;
+
+export function unifyValidatePassword(pwd) {
+  const reasons = [];
+
+  // 1) 长度校验:8-20
+  if (pwd.length < 8) {
+    reasons.push('密码长度不能小于8位');
+  } else if (pwd.length > 20) {
+    reasons.push('密码长度不能超过20位');
+  }
+
+  // 2) 统计字符类别命中数(四类中至少两类)
+  const hasDigit = DIGIT_CLASS.test(pwd);
+  const hasLower = LOWER_CLASS.test(pwd);
+  const hasUpper = UPPER_CLASS.test(pwd);
+  const hasSpecial = SPECIAL_CHAR_CLASS.test(pwd);
+
+  const typeCount = [hasDigit, hasLower, hasUpper, hasSpecial].filter(Boolean).length;
+
+  if (typeCount < 2) {
+    reasons.push('密码必须同时包含数字、字母、特殊字符中的两种');
+  }
+
+  if (SPACE_REG.test(pwd)) {
+    reasons.push('密码不能包含空格');
+  }
+
+  // 4) 可选:若只想限定在“允许字符集合”内,打开 ALLOWED_ALL 后使用以下判断
+  // if (!ALLOWED_ALL.test(pwd)) {
+  //   reasons.push("密码包含不被允许的字符。");
+  // }
+
+  return {
+    ok: reasons.length === 0,
+    reasons,
+  };
+}