Commit 34fb2562 authored by 刘帅's avatar 刘帅

1.新用户创建以及管理员密码重置增加规则校验

parent 9c5cdb29
...@@ -260,7 +260,7 @@ ...@@ -260,7 +260,7 @@
</el-col> </el-col>
<el-col :span="12"> <el-col :span="12">
<el-form-item v-if="form.userId == undefined" label="用户密码" prop="password"> <el-form-item v-if="form.userId == undefined" label="用户密码" prop="password">
<el-input v-model="form.password" placeholder="请输入用户密码" type="password" maxlength="20" show-password/> <el-input v-model="form.password" placeholder="请输入用户密码" type="password" maxlength="20" show-password @input="checkPasswordStrength"/>
</el-form-item> </el-form-item>
</el-col> </el-col>
</el-row> </el-row>
...@@ -385,7 +385,30 @@ export default { ...@@ -385,7 +385,30 @@ export default {
dicts: ['sys_normal_disable', 'sys_user_sex'], dicts: ['sys_normal_disable', 'sys_user_sex'],
components: { Treeselect }, components: { Treeselect },
data() { 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 { return {
strengthClass: 'weak',
strengthText: '',
isPasswordStrong: false,
// 遮罩层 // 遮罩层
loading: true, loading: true,
// 选中数组 // 选中数组
...@@ -468,7 +491,8 @@ export default { ...@@ -468,7 +491,8 @@ export default {
], ],
password: [ password: [
{ required: true, message: "用户密码不能为空", trigger: "blur" }, { 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: [ email: [
{ {
...@@ -501,6 +525,40 @@ export default { ...@@ -501,6 +525,40 @@ export default {
}); });
}, },
methods: { 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() { getList() {
this.loading = true; this.loading = true;
...@@ -625,8 +683,8 @@ export default { ...@@ -625,8 +683,8 @@ export default {
confirmButtonText: "确定", confirmButtonText: "确定",
cancelButtonText: "取消", cancelButtonText: "取消",
closeOnClickModal: false, closeOnClickModal: false,
inputPattern: /^.{5,20}$/, inputPattern: /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,20}$/,
inputErrorMessage: "用户密码长度必须介于 5 和 20 之间" inputErrorMessage: "密码必须为8-20个字符,且包含大写字母、小写字母、数字和特殊字符(@$!%*?&)"
}).then(({ value }) => { }).then(({ value }) => {
resetUserPwd(row.userId, value).then(response => { resetUserPwd(row.userId, value).then(response => {
this.$modal.msgSuccess("修改成功,新密码是:" + value); this.$modal.msgSuccess("修改成功,新密码是:" + value);
......
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