重置密码强度校验
This commit is contained in:
@@ -35,12 +35,42 @@ const UpdateForm: React.FC<UpdateFormProps> = (props) => {
|
|||||||
props.onSubmit({ ...values, userId } as FormValueType);
|
props.onSubmit({ ...values, userId } as FormValueType);
|
||||||
};
|
};
|
||||||
|
|
||||||
const checkPassword = (rule: any, value: string) => {
|
// 密码强度校验
|
||||||
if (value === loginPassword) {
|
const validatePasswordStrength = (rule: any, value: string) => {
|
||||||
// 校验条件自定义
|
if (!value) {
|
||||||
return Promise.resolve();
|
return Promise.reject(new Error('登录密码不可为空。'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (value.length < 8) {
|
||||||
|
return Promise.reject(new Error('密码长度至少8位。'));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查密码复杂度:至少包含大小写字母、数字、特殊字符中的三种
|
||||||
|
const hasLowerCase = /[a-z]/.test(value);
|
||||||
|
const hasUpperCase = /[A-Z]/.test(value);
|
||||||
|
const hasNumber = /[0-9]/.test(value);
|
||||||
|
const hasSpecialChar = /[!@#$%^&*()_+\-=[\]{};':"\\|,.<>/?]/.test(value);
|
||||||
|
|
||||||
|
const complexityCount = [hasLowerCase, hasUpperCase, hasNumber, hasSpecialChar].filter(Boolean).length;
|
||||||
|
|
||||||
|
if (complexityCount < 3) {
|
||||||
|
return Promise.reject(new Error('密码需包含大小写字母、数字、特殊字符中的至少三种。'));
|
||||||
|
}
|
||||||
|
|
||||||
|
return Promise.resolve();
|
||||||
|
};
|
||||||
|
|
||||||
|
// 确认密码校验
|
||||||
|
const checkPassword = (rule: any, value: string) => {
|
||||||
|
if (!value) {
|
||||||
|
return Promise.reject(new Error('确认密码不可为空。'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value !== loginPassword) {
|
||||||
return Promise.reject(new Error('两次密码输入不一致'));
|
return Promise.reject(new Error('两次密码输入不一致'));
|
||||||
|
}
|
||||||
|
|
||||||
|
return Promise.resolve();
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -71,21 +101,20 @@ const UpdateForm: React.FC<UpdateFormProps> = (props) => {
|
|||||||
label="登录密码"
|
label="登录密码"
|
||||||
rules={[
|
rules={[
|
||||||
{
|
{
|
||||||
required: true,
|
validator: validatePasswordStrength,
|
||||||
message: '登录密码不可为空。',
|
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
|
placeholder="请输入新密码"
|
||||||
/>
|
/>
|
||||||
<ProFormText.Password
|
<ProFormText.Password
|
||||||
name="confirm_password"
|
name="confirm_password"
|
||||||
label="确认密码"
|
label="确认密码"
|
||||||
rules={[
|
rules={[
|
||||||
{
|
{
|
||||||
required: true,
|
validator: checkPassword,
|
||||||
message: "确认密码",
|
|
||||||
},
|
},
|
||||||
{ validator: checkPassword },
|
|
||||||
]}
|
]}
|
||||||
|
placeholder="请再次输入密码"
|
||||||
/>
|
/>
|
||||||
</ProForm>
|
</ProForm>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
|||||||
@@ -100,6 +100,7 @@ export function resetUserPwd(userId: number, password: string) {
|
|||||||
return request<API.Result>('/api/system/user/resetPwd', {
|
return request<API.Result>('/api/system/user/resetPwd', {
|
||||||
method: 'put',
|
method: 'put',
|
||||||
data: data,
|
data: data,
|
||||||
|
isEncrypt: true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user