From 63ce31150e32fafe214105afb18e1bf2eace0dc1 Mon Sep 17 00:00:00 2001
From: 张含笑 <zhx18749296735@163.com>
Date: Mon, 03 Nov 2025 10:45:14 +0800
Subject: [PATCH] feat:修改密码限制

---
 src/views/system/userinfo.vue |   43 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 43 insertions(+), 0 deletions(-)

diff --git a/src/views/system/userinfo.vue b/src/views/system/userinfo.vue
index 113c02f..89bc9cf 100644
--- a/src/views/system/userinfo.vue
+++ b/src/views/system/userinfo.vue
@@ -165,6 +165,29 @@
 	}
 	return true
 }
+// 校验密码不能包含中文
+const validatePasswordNoChinese = (password) => {
+  const chineseRegex = /[\u4e00-\u9fa5]/;
+  if (chineseRegex.test(password)) {
+    ElMessage.error('密码不能包含中文字符');
+    return false;
+  }
+  return true;
+};
+// 校验密码复杂度(长度≥6位,包含字母和数字)
+const validatePasswordStrength = (password) => {
+  if (password.length < 6) {
+    ElMessage.error('密码长度不能少于6位');
+    return false;
+  }
+  // const hasLetter = /[a-zA-Z]/.test(password);
+  // const hasNumber = /\d/.test(password);
+  // if (!hasLetter || !hasNumber) {
+  //   ElMessage.error('密码需同时包含字母和数字');
+  //   return false;
+  // }
+  return true;
+};
 const passwordForm = ref({
   oldPassword: '',
   newPassword: '',
@@ -245,6 +268,26 @@
       }
     });
   } else if (checked.value === 1) {
+   // 原始密码校验
+    if (!passwordForm.value.oldPassword) {
+      ElMessage.error('请输入原始密码');
+      return;
+    }
+     // 中文校验
+    if (!validatePasswordNoChinese(passwordForm.value.newPassword)) return;
+    // 新密码校验
+    if (!passwordForm.value.newPassword) {
+      ElMessage.error('请输入新密码');
+      return;
+    }
+    // 确认密码校验
+    if (passwordForm.value.newPassword !== passwordForm.value.newPassword1) {
+      ElMessage.error('两次输入的新密码不一致');
+      return;
+    }
+   
+    // 复杂度校验
+    if (!validatePasswordStrength(passwordForm.value.newPassword)) return;
     updatePassword(
       md5(passwordForm.value.oldPassword),
       md5(passwordForm.value.newPassword),

--
Gitblit v1.9.3