用户登录问题修改
This commit is contained in:
parent
be94bc276f
commit
d0b5d6c704
|
|
@ -14,7 +14,10 @@ const DATA_SETTINGS = {
|
|||
|
||||
// SM 配置
|
||||
const SM_CONFIG = {
|
||||
SALT: '2cc0c5f9f1749f1632efa9f63e902323' // SM3 盐值(16 字节)
|
||||
SALT: '2cc0c5f9f1749f1632efa9f63e902323', // SM3 盐值(16 字节)
|
||||
SM4_KEY: 'your-sm4-key', // SM4 对称加密密钥
|
||||
SM2_PUBLIC_KEY: 'your-public-key', // SM2 公钥
|
||||
SM2_PRIVATE_KEY: 'your-private-key' // SM2 私钥
|
||||
}
|
||||
|
||||
// AES 配置
|
||||
|
|
|
|||
|
|
@ -6,7 +6,10 @@ export default {
|
|||
requireLowerCase: true, // 是否需要小写字母
|
||||
requireDigit: true, // 是否需要数字
|
||||
requireSpecialChar: true, // 是否需要特殊字符
|
||||
weakPasswords: ['123456', 'password', 'qwerty'], // 弱密码列表
|
||||
weakPasswords: [ "111", "888", "123", "234", "345", "456", "567", "678", "789", "1234",
|
||||
"2345", "3456", "4567", "5678", "6789", "abc", "abcd", "abcde", "abcdef", "abcdefg",
|
||||
"qwe", "qwer", "qwert", "qwerty", "asdf", "asdfg", "asdfgh", "password", "passw0rd",
|
||||
"letmein", "welcome", "admin", "user", "test", "pass", "root", "login"], // 弱密码列表
|
||||
restrictConsecutiveChars: true, // 是否限制连续字符
|
||||
maxConsecutiveChars: 3, // 最大连续字符数
|
||||
excludeUsernameInPassword: true, // 是否不允许密码包含用户名
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
// src/utils/encryption.js
|
||||
import sm3 from 'sm-crypto/src/sm3'
|
||||
import { sm2, sm3, sm4 } from 'sm-crypto'
|
||||
// 配置项,例如盐值、SM2 公私钥、SM4 密钥
|
||||
import { SM_CONFIG } from './configure'
|
||||
|
||||
|
||||
// SM3 哈希
|
||||
export function hashSM3(text) {
|
||||
// 对数据进行哈希计算
|
||||
|
|
@ -15,3 +17,27 @@ export function hashWithSM3AndSalt(text) {
|
|||
// 使用 SM3 进行哈希
|
||||
return hashSM3(textWithSalt)
|
||||
}
|
||||
|
||||
// SM2 加密
|
||||
export function encryptWithSM2(text) {
|
||||
// SM2 公钥加密
|
||||
return sm2.doEncrypt(text, SM_CONFIG.SM2_PUBLIC_KEY)
|
||||
}
|
||||
|
||||
// SM2 解密
|
||||
export function decryptWithSM2(encryptedText) {
|
||||
// SM2 私钥解密
|
||||
return sm2.doDecrypt(encryptedText, SM_CONFIG.SM2_PRIVATE_KEY)
|
||||
}
|
||||
|
||||
// SM4 加密
|
||||
export function encryptWithSM4(text) {
|
||||
// SM4 对称加密,ECB 模式
|
||||
return sm4.encrypt(text, SM_CONFIG.SM4_KEY)
|
||||
}
|
||||
|
||||
// SM4 解密
|
||||
export function decryptWithSM4(encryptedText) {
|
||||
// SM4 对称解密,ECB 模式
|
||||
return sm4.decrypt(encryptedText, SM_CONFIG.SM4_KEY)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -184,7 +184,8 @@ export function validateNewPassword(rule, value, callback) {
|
|||
}
|
||||
// 3. 检查是否包含弱密码
|
||||
for (const weakPwd of passwordConfig.weakPasswords) {
|
||||
if (value.includes(weakPwd)) {
|
||||
// 将密码和弱密码都转换为小写进行比较
|
||||
if (value.toLowerCase().includes(weakPwd.toLowerCase())) {
|
||||
callback(new Error(`密码包含常见的弱密码片段: ${weakPwd}`))
|
||||
return
|
||||
}
|
||||
|
|
@ -198,14 +199,51 @@ export function validateNewPassword(rule, value, callback) {
|
|||
}
|
||||
|
||||
function 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 = ""; // 保存上一个字符
|
||||
|
||||
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; // 如果没有找到问题,则返回符合要求的提示
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue