张含笑
2025-11-03 18f57480d27631d022cee275b4a4e193d39955cd
feat:密码校验
1 files modified
67 ■■■■■ changed files
src/subPackages/userDetail/password/index.vue 67 ●●●●● patch | view | raw | blame | history
src/subPackages/userDetail/password/index.vue
@@ -49,6 +49,39 @@
        newPassword: '',
        newPassword1: '',
    });
    // 校验密码不能包含中文
    const validatePasswordNoChinese = (password) => {
      const chineseRegex = /[\u4e00-\u9fa5]/;
      if (chineseRegex.test(password)) {
        uni.showToast({
            title: '密码不能包含中文字符',
            icon: 'none',
            duration: 2000
        });
        return false;
      }
      return true;
    };
    // 校验密码复杂度(长度≥6位,包含字母和数字)
    const validatePasswordStrength = (password) => {
      if (password.length < 6) {
        uni.showToast({
            title: '密码长度不能少于6位',
            icon: 'none',
            duration: 2000
        });
        return false;
      }
      // const hasLetter = /[a-zA-Z]/.test(password);
      // const hasNumber = /\d/.test(password);
      // if (!hasLetter || !hasNumber) {
      //   ElMessage.error('密码需同时包含字母和数字');
      //   return false;
      // }
      return true;
    };
    const clearForm = () => {
        passwordForm.value = {
            oldPassword: '',
@@ -60,7 +93,41 @@
        clearForm();
    };
    const submit = () => {
// 原始密码校验
    if (!passwordForm.value.oldPassword) {
      uni.showToast({
          title: '请输入原始密码',
          icon: 'none',
          duration: 2000
      });
      return;
    }
     // 中文校验
    if (!validatePasswordNoChinese(passwordForm.value.newPassword)) return;
    // 新密码校验
    if (!passwordForm.value.newPassword) {
      uni.showToast({
          title: '请输入新密码',
          icon: 'none',
          duration: 2000
      });
      return;
    }
    // 确认密码校验
    if (passwordForm.value.newPassword !== passwordForm.value.newPassword1) {
      uni.showToast({
          title: '两次输入的新密码不一致',
          icon: 'none',
          duration: 2000
      });
      return;
    }
    // 复杂度校验
    if (!validatePasswordStrength(passwordForm.value.newPassword)) return;
        updatePassword(md5(passwordForm.value.oldPassword),
            md5(passwordForm.value.newPassword),
            md5(passwordForm.value.newPassword1)).then(res => {