From 305a665da20216b4609194d5ddb5fdd2ba4f2453 Mon Sep 17 00:00:00 2001 From: jiang Date: Sat, 14 Sep 2024 17:34:19 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=99=BB=E5=BD=95=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/system/user/index.vue | 51 +++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 8 deletions(-) diff --git a/src/views/system/user/index.vue b/src/views/system/user/index.vue index 9fe1de45..c31512fe 100644 --- a/src/views/system/user/index.vue +++ b/src/views/system/user/index.vue @@ -743,18 +743,53 @@ export default { // 6. 新密码通过所有校验,返回空表示通过校验 return null }, - containsConsecutiveCharacters(password, maxConsecutive) { - let count = 1 - for (let i = 1; i < password.length; i++) { - if (password[i] === password[i - 1]) { - count++ - if (count > maxConsecutive) return true + let count = 1 // 初始化计数器 + let previousChar = '' // 保存上一个字符 + maxConsecutive = maxConsecutive + 1 + for (let i = 0; i < password.length; i++) { + // 检查当前字符与前一个字符是否相同 + if (password[i] === previousChar) { + count++ // 计数器加1 } else { - count = 1 + count = 1 // 如果字符不同,重置计数器 } + + // 检查是否超过最大连续字符数 + if (count > maxConsecutive) { + return true + } + + // 检查当前字符是否是数字 + if (/\d/.test(password[i])) { + // 检查是否有超过指定数量的连续数字 + if (i > 0 && password[i] === password[i - 1]) { + count++ // 计数器加1 + if (count > maxConsecutive) { + return true + } + } else { + count = 1 // 重置计数器 + } + } + + // 检查当前字符是否是字母 + if (/[a-zA-Z]/.test(password[i])) { + // 检查是否有超过指定数量的连续字母 + if (i > 0 && password[i] === password[i - 1]) { + count++ // 计数器加1 + if (count > maxConsecutive) { + return true + } + } else { + count = 1 // 重置计数器 + } + } + + previousChar = password[i] // 更新上一个字符 } - return false + + return false // 如果没有找到问题,则返回符合要求的提示 } } }