重置密码强度校验
This commit is contained in:
@@ -35,12 +35,42 @@ const UpdateForm: React.FC<UpdateFormProps> = (props) => {
|
||||
props.onSubmit({ ...values, userId } as FormValueType);
|
||||
};
|
||||
|
||||
const checkPassword = (rule: any, value: string) => {
|
||||
if (value === loginPassword) {
|
||||
// 校验条件自定义
|
||||
return Promise.resolve();
|
||||
// 密码强度校验
|
||||
const validatePasswordStrength = (rule: any, value: string) => {
|
||||
if (!value) {
|
||||
return Promise.reject(new Error('登录密码不可为空。'));
|
||||
}
|
||||
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.resolve();
|
||||
};
|
||||
|
||||
return (
|
||||
@@ -71,25 +101,24 @@ const UpdateForm: React.FC<UpdateFormProps> = (props) => {
|
||||
label="登录密码"
|
||||
rules={[
|
||||
{
|
||||
required: true,
|
||||
message: '登录密码不可为空。',
|
||||
validator: validatePasswordStrength,
|
||||
},
|
||||
]}
|
||||
placeholder="请输入新密码"
|
||||
/>
|
||||
<ProFormText.Password
|
||||
name="confirm_password"
|
||||
label="确认密码"
|
||||
rules={[
|
||||
{
|
||||
required: true,
|
||||
message: "确认密码",
|
||||
validator: checkPassword,
|
||||
},
|
||||
{ validator: checkPassword },
|
||||
]}
|
||||
placeholder="请再次输入密码"
|
||||
/>
|
||||
</ProForm>
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
|
||||
export default UpdateForm;
|
||||
export default UpdateForm;
|
||||
Reference in New Issue
Block a user