diff --git a/maintain-ui/src/views/login.vue b/maintain-ui/src/views/login.vue index 88a03a5036eb204ad518cad3e6f5e3784bd66f7c..d0b6577b2330403de3d06741211abdfc3cdf57ba 100644 --- a/maintain-ui/src/views/login.vue +++ b/maintain-ui/src/views/login.vue @@ -19,6 +19,7 @@ auto-complete="off" placeholder="密码" @keyup.enter.native="handleLogin" + @input="checkPasswordStrength" > @@ -120,6 +121,26 @@ export default { this.getCookie(); }, methods: { + // 检查密码强度 + checkPasswordStrength() { + if (!this.loginForm.password) { + this.isPasswordStrong = false; + return; + } + let strength = 0; + // 长度检查 + if (this.loginForm.password.length >= 8) strength++; + // 包含小写字母 + if (/[a-z]/.test(this.loginForm.password)) strength++; + // 包含大写字母 + if (/[A-Z]/.test(this.loginForm.password)) strength++; + // 包含数字 + if (/[0-9]/.test(this.loginForm.password)) strength++; + // 包含特殊字符 + if (/[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]/.test(this.loginForm.password)) strength++; + // 设置强度等级 + this.isPasswordStrong = strength > 4; + }, getCode() { getCodeImg().then(res => { this.captchaEnabled = res.data.captchaEnabled === undefined ? true : res.data.captchaEnabled; @@ -142,6 +163,11 @@ export default { handleLogin() { this.$refs.loginForm.validate(valid => { if (valid) { + // 再次确认密码强度 + if (!this.isPasswordStrong) { + this.$message.error("密码强度不足,请确保包含大小写字母、数字和特殊字符"); + return; + } this.loading = true; if (this.loginForm.rememberMe) { Cookies.set("username", this.loginForm.username, { expires: 30 });