用户登录问题修改

This commit is contained in:
jiang 2024-09-18 15:51:58 +08:00
parent 305a665da2
commit 4a84ccb7db
2 changed files with 141 additions and 84 deletions

View File

@ -198,52 +198,81 @@ export function validateNewPassword(rule, value, callback) {
callback() // 验证成功 callback() // 验证成功
} }
function containsConsecutiveCharacters(password, maxConsecutive) { /**
let count = 1 // 初始化计数器 * 检查密码中是否包含超过 n 个连续相同字符连续递增/递减的数字或字母不区分大小写
let previousChar = '' // 保存上一个字符 */
maxConsecutive = maxConsecutive + 1 function containsConsecutiveCharacters(password, n) {
for (let i = 0; i < password.length; i++) { // 检查连续相同字符
// 检查当前字符与前一个字符是否相同 n = n + 1; // 允许最多 n 个连续字符
if (password[i] === previousChar) { for (let i = 0; i <= password.length - n; i++) {
count++ // 计数器加1 let consecutiveSameChar = true;
} else { for (let j = 1; j < n; j++) {
count = 1 // 如果字符不同,重置计数器 if (password[i + j] !== password[i]) {
consecutiveSameChar = false;
break;
}
}
if (consecutiveSameChar) {
return true; // 包含超过 n 个连续相同字符
}
} }
// 检查是否超过最大连续字符数 // 检查连续递增或递减的数字
if (count > maxConsecutive) { for (let i = 0; i <= password.length - n; i++) {
return true let consecutiveIncreasing = true;
} let consecutiveDecreasing = true;
for (let j = 1; j < n; j++) {
const currentChar = password[i];
const nextChar = password[i + j];
// 检查当前字符是否是数字 // 检查数字递增或递减
if (/\d/.test(password[i])) { if (/\d/.test(currentChar) && /\d/.test(nextChar)) {
// 检查是否有超过指定数量的连续数字 if (nextChar.charCodeAt(0) !== currentChar.charCodeAt(0) + j) {
if (i > 0 && password[i] === password[i - 1]) { consecutiveIncreasing = false;
count++ // 计数器加1 }
if (count > maxConsecutive) { if (nextChar.charCodeAt(0) !== currentChar.charCodeAt(0) - j) {
return true consecutiveDecreasing = false;
} }
} else { } else {
count = 1 // 重置计数器 consecutiveIncreasing = false;
consecutiveDecreasing = false;
break;
}
}
if (consecutiveIncreasing || consecutiveDecreasing) {
return true; // 包含超过 n 个递增或递减的连续数字
} }
} }
// 检查当前字符是否是字母 // 检查连续递增或递减的字母(不区分大小写)
if (/[a-zA-Z]/.test(password[i])) { for (let i = 0; i <= password.length - n; i++) {
// 检查是否有超过指定数量的连续字母 let consecutiveIncreasing = true;
if (i > 0 && password[i] === password[i - 1]) { let consecutiveDecreasing = true;
count++ // 计数器加1 for (let j = 1; j < n; j++) {
if (count > maxConsecutive) { const currentChar = password[i].toLowerCase(); // 转为小写
return true const nextChar = password[i + j].toLowerCase(); // 转为小写
// 检查字母递增或递减
if (/[a-zA-Z]/.test(currentChar) && /[a-zA-Z]/.test(nextChar)) {
if (nextChar.charCodeAt(0) !== currentChar.charCodeAt(0) + j) {
consecutiveIncreasing = false;
}
if (nextChar.charCodeAt(0) !== currentChar.charCodeAt(0) - j) {
consecutiveDecreasing = false;
} }
} else { } else {
count = 1 // 重置计数器 consecutiveIncreasing = false;
consecutiveDecreasing = false;
break;
}
}
if (consecutiveIncreasing || consecutiveDecreasing) {
return true; // 包含超过 n 个递增或递减的连续字母
} }
} }
previousChar = password[i] // 更新上一个字符 // 不包含连续相同字符、数字或字母序列
return false;
} }
return false // 如果没有找到问题,则返回符合要求的提示
}

View File

@ -743,53 +743,81 @@ export default {
// 6. // 6.
return null return null
}, },
containsConsecutiveCharacters(password, maxConsecutive) { /**
let count = 1 // * 检查密码中是否包含超过 n 个连续相同字符连续递增/递减的数字或字母不区分大小写
let previousChar = '' // */
maxConsecutive = maxConsecutive + 1 containsConsecutiveCharacters(password, n) {
for (let i = 0; i < password.length; i++) { //
// n = n + 1 // n
if (password[i] === previousChar) { for (let i = 0; i <= password.length - n; i++) {
count++ // 1 let consecutiveSameChar = true
} else { for (let j = 1; j < n; j++) {
count = 1 // if (password[i + j] !== password[i]) {
consecutiveSameChar = false
break
}
}
if (consecutiveSameChar) {
return true // n
}
} }
// //
if (count > maxConsecutive) { for (let i = 0; i <= password.length - n; i++) {
return true let consecutiveIncreasing = true
} let consecutiveDecreasing = true
for (let j = 1; j < n; j++) {
const currentChar = password[i]
const nextChar = password[i + j]
// //
if (/\d/.test(password[i])) { if (/\d/.test(currentChar) && /\d/.test(nextChar)) {
// if (nextChar.charCodeAt(0) !== currentChar.charCodeAt(0) + j) {
if (i > 0 && password[i] === password[i - 1]) { consecutiveIncreasing = false
count++ // 1 }
if (count > maxConsecutive) { if (nextChar.charCodeAt(0) !== currentChar.charCodeAt(0) - j) {
return true consecutiveDecreasing = false
} }
} else { } else {
count = 1 // consecutiveIncreasing = false
consecutiveDecreasing = false
break
}
}
if (consecutiveIncreasing || consecutiveDecreasing) {
return true // n
} }
} }
// //
if (/[a-zA-Z]/.test(password[i])) { for (let i = 0; i <= password.length - n; i++) {
// let consecutiveIncreasing = true
if (i > 0 && password[i] === password[i - 1]) { let consecutiveDecreasing = true
count++ // 1 for (let j = 1; j < n; j++) {
if (count > maxConsecutive) { const currentChar = password[i].toLowerCase() //
return true const nextChar = password[i + j].toLowerCase() //
//
if (/[a-zA-Z]/.test(currentChar) && /[a-zA-Z]/.test(nextChar)) {
if (nextChar.charCodeAt(0) !== currentChar.charCodeAt(0) + j) {
consecutiveIncreasing = false
}
if (nextChar.charCodeAt(0) !== currentChar.charCodeAt(0) - j) {
consecutiveDecreasing = false
} }
} else { } else {
count = 1 // consecutiveIncreasing = false
consecutiveDecreasing = false
break
}
}
if (consecutiveIncreasing || consecutiveDecreasing) {
return true // n
} }
} }
previousChar = password[i] // //
} return false
return false //
} }
} }
} }