Commit c60793a8 authored by 刘帅's avatar 刘帅

1.用户登录输入密码进行规则校验

parent ec98a0ca
......@@ -19,6 +19,7 @@
auto-complete="off"
placeholder="密码"
@keyup.enter.native="handleLogin"
@input="checkPasswordStrength"
>
<svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" />
</el-input>
......@@ -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 });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment