diff --git a/maintain-ui/src/views/system/user/index.vue b/maintain-ui/src/views/system/user/index.vue index 280689ee10ddaa171dddf0e900bb179323eab664..ac635239a2ade665e723c1deb25f40ec3cf4b2db 100644 --- a/maintain-ui/src/views/system/user/index.vue +++ b/maintain-ui/src/views/system/user/index.vue @@ -260,7 +260,7 @@ - + @@ -385,7 +385,30 @@ export default { dicts: ['sys_normal_disable', 'sys_user_sex'], components: { Treeselect }, data() { + // 验证密码复杂度 + const validatePasswordComplexity = (rule, value, callback) => { + if (!value) { + callback(new Error("新密码不能为空")); + return; + } + + // 检查密码复杂度 + const hasLowerCase = /[a-z]/.test(value); + const hasUpperCase = /[A-Z]/.test(value); + const hasNumber = /[0-9]/.test(value); + const hasSpecialChar = /[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]/.test(value); + + if (!hasLowerCase || !hasUpperCase || !hasNumber || !hasSpecialChar) { + callback(new Error("密码必须包含大小写字母、数字和特殊字符")); + return; + } + + callback(); + }; return { + strengthClass: 'weak', + strengthText: '弱', + isPasswordStrong: false, // 遮罩层 loading: true, // 选中数组 @@ -468,7 +491,8 @@ export default { ], password: [ { required: true, message: "用户密码不能为空", trigger: "blur" }, - { min: 5, max: 20, message: '用户密码长度必须介于 5 和 20 之间', trigger: 'blur' } + { min: 8, message: "密码至少为8个字符,须包含大写字母、小写字母、数字和特殊字符", trigger: "blur" }, + { validator: validatePasswordComplexity, trigger: "blur" } ], email: [ { @@ -501,6 +525,40 @@ export default { }); }, methods: { + // 检查密码强度 + checkPasswordStrength() { + if (!this.form.password) { + this.strengthClass = 'weak'; + this.strengthText = '弱'; + this.isPasswordStrong = false; + return; + } + let strength = 0; + // 长度检查 + if (this.form.password.length >= 8) strength++; + // 包含小写字母 + if (/[a-z]/.test(this.form.password)) strength++; + // 包含大写字母 + if (/[A-Z]/.test(this.form.password)) strength++; + // 包含数字 + if (/[0-9]/.test(this.form.password)) strength++; + // 包含特殊字符 + if (/[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]/.test(this.form.password)) strength++; + // 设置强度等级 + if (strength <= 2) { + this.strengthClass = 'weak'; + this.strengthText = '弱'; + this.isPasswordStrong = false; + } else if (strength <= 4) { + this.strengthClass = 'medium'; + this.strengthText = '中'; + this.isPasswordStrong = false; + } else { + this.strengthClass = 'strong'; + this.strengthText = '强'; + this.isPasswordStrong = true; + } + }, /** 查询用户列表 */ getList() { this.loading = true; @@ -625,13 +683,13 @@ export default { confirmButtonText: "确定", cancelButtonText: "取消", closeOnClickModal: false, - inputPattern: /^.{5,20}$/, - inputErrorMessage: "用户密码长度必须介于 5 和 20 之间" + inputPattern: /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,20}$/, + inputErrorMessage: "密码必须为8-20个字符,且包含大写字母、小写字母、数字和特殊字符(@$!%*?&)" }).then(({ value }) => { - resetUserPwd(row.userId, value).then(response => { - this.$modal.msgSuccess("修改成功,新密码是:" + value); - }); - }).catch(() => {}); + resetUserPwd(row.userId, value).then(response => { + this.$modal.msgSuccess("修改成功,新密码是:" + value); + }); + }).catch(() => {}); }, /** 分配角色操作 */ handleAuthRole: function(row) {