|
@@ -505,3 +505,56 @@ export function calcMallUrlCatName(val){
|
|
|
let current = a[0]
|
|
|
return current
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+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 L = getCurLanguage();
|
|
|
+ const reasons = [];
|
|
|
+
|
|
|
+ // 1) 长度校验:8-20
|
|
|
+ if (pwd.length < 8) {
|
|
|
+ reasons.push(L['register']["密码长度不能小于8位"]);
|
|
|
+ } else if (pwd.length > 20) {
|
|
|
+ reasons.push(L['register']['密码长度不能超过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(L['register']['密码必须同时包含数字、字母、特殊字符中的两种']);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (SPACE_REG.test(pwd)) {
|
|
|
+ reasons.push(L['register']['密码不能包含空格']);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 4) 可选:若只想限定在“允许字符集合”内,打开 ALLOWED_ALL 后使用以下判断
|
|
|
+ // if (!ALLOWED_ALL.test(pwd)) {
|
|
|
+ // reasons.push("密码包含不被允许的字符。");
|
|
|
+ // }
|
|
|
+
|
|
|
+ return {
|
|
|
+ ok: reasons.length === 0,
|
|
|
+ reasons,
|
|
|
+ };
|
|
|
+}
|
|
|
+
|