Skip to content

Commit

Permalink
improve(): Password verification rules
Browse files Browse the repository at this point in the history
  • Loading branch information
TianWuwt committed Sep 9, 2024
1 parent 0a29013 commit 7fc247c
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 19 deletions.
13 changes: 4 additions & 9 deletions ui/src/components/customModal/HandleAccountModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import type { AcAccount, AcCreateAccountParam } from '@/api/generated';
import { encryptText, usePublicKey } from '@/hook/usePublicKey';
import { Type } from '@/pages/Access/type';
import { intl } from '@/utils/intl';
import { passwordRules } from '@/utils';
import { useModel } from '@umijs/max';
import { useRequest } from 'ahooks';
import { Form, Input, Select, message } from 'antd';
import { omit } from 'lodash';
import { useEffect, useMemo } from 'react';
import CustomModal from '.';


interface HandleRoleModalProps {
visible: boolean;
setVisible: (visible: boolean) => void;
Expand All @@ -28,6 +30,7 @@ export default function HandleAccountModal({
const [form] = Form.useForm();
const { refresh } = useModel('@@initialState');
const publicKey = usePublicKey();

const handleSubmit = async () => {
try {
await form.validateFields();
Expand Down Expand Up @@ -198,15 +201,7 @@ export default function HandleAccountModal({

{type === Type.CREATE && (
<Form.Item
rules={[
{
required: true,
message: intl.formatMessage({
id: 'src.components.customModal.5B73A2BF',
defaultMessage: '请输入',
}),
},
]}
rules={passwordRules}
label={intl.formatMessage({
id: 'src.components.customModal.966B1EBB',
defaultMessage: '密码',
Expand Down
12 changes: 3 additions & 9 deletions ui/src/components/customModal/ModifyPasswordModal.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { encryptText, usePublicKey } from '@/hook/usePublicKey';
import { changeTenantPassword } from '@/services/tenant';
import { intl } from '@/utils/intl';
import { passwordRules } from '@/utils';
import { useParams } from '@umijs/max';
import { Form, Input, message } from 'antd';

import CustomModal from '.';


type FieldType = {
Password: string;
};
Expand Down Expand Up @@ -69,15 +71,7 @@ export default function ModifyPasswordModal({
defaultMessage: '输入新密码',
})}
name="password"
rules={[
{
required: true,
message: intl.formatMessage({
id: 'Dashboard.components.customModal.ModifyPasswordModal.PleaseEnter',
defaultMessage: '请输入',
}),
},
]}
rules={passwordRules}
>
<Input.Password
placeholder={intl.formatMessage({
Expand Down
51 changes: 51 additions & 0 deletions ui/src/components/customModal/ResetPwdModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,57 @@ export default function ResetPwdModal({
defaultMessage: '请输入',
}),
},
() => ({
validator(_: any, value: string) {
if (value.length >= 8 && value.length <= 32) {
return Promise.resolve();
}
return Promise.reject(
new Error(
intl.formatMessage({
id: 'OBDashboard.Cluster.New.helper.ToCharactersInLength',
defaultMessage: '长度为 8~32 个字符',
}),
),
);
},
}),
() => ({
validator(_: any, value: string) {
const regex = /^[a-zA-Z0-9~!@#%^&*\-_+=|(){}[\]:;,.?/`$"<>]+$/;
if (regex.test(value)) {
return Promise.resolve();
}
return Promise.reject(
new Error(
intl.formatMessage({
id: 'OBDashboard.Cluster.New.helper.CanOnlyContainLettersNumbers',
defaultMessage:
'只能包含字母、数字和特殊字符(~!@#%^&*_-+=|(){}[]:;,.?/`$"<>)',
}),
),
);
},
}),
() => ({
validator(_: any, value: string) {
if (
/^(?=(.*[a-z]){2,})(?=(.*[A-Z]){2,})(?=(.*\d){2,})(?=(.*[~!@#%^&*_\-+=|(){}[\]:;,.?/`$'"<>\\]){2,})[A-Za-z\d~!@#%^&*_\-+=|(){}[\]:;,.?/`$'"<>\\]{2,}$/.test(
value,
)
) {
return Promise.resolve();
}
return Promise.reject(
new Error(
intl.formatMessage({
id: 'OBDashboard.Cluster.New.helper.AtLeastUppercaseAndLowercase',
defaultMessage: '大小写字母、数字和特殊字符都至少包含 2 个',
}),
),
);
},
}),
({ getFieldValue }) => ({
validator(_, value) {
const oldPwd = getFieldValue('oldPassword');
Expand Down
2 changes: 1 addition & 1 deletion ui/src/pages/OBProxy/New/BasicConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import IconTip from '@/components/IconTip';
import SelectNSFromItem from '@/components/SelectNSFromItem';
import TooltipPretty from '@/components/TooltipPretty';
import { resourceNameRule } from '@/constants/rules';
import { passwordRules } from '@/pages/Cluster/New/helper';
import { passwordRules } from '@/utils';
import { getSimpleClusterList } from '@/services';
import { intl } from '@/utils/intl';
import { useRequest } from 'ahooks';
Expand Down
63 changes: 63 additions & 0 deletions ui/src/utils/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { intl } from '@/utils/intl';


export const passwordRules = [
{
required: true,
message: intl.formatMessage({
id: 'OBDashboard.Cluster.New.helper.EnterAPassword',
defaultMessage: '请输入密码',
}),
},
() => ({
validator(_: any, value: string) {
if (value.length >= 8 && value.length <= 32) {
return Promise.resolve();
}
return Promise.reject(
new Error(
intl.formatMessage({
id: 'OBDashboard.Cluster.New.helper.ToCharactersInLength',
defaultMessage: '长度为 8~32 个字符',
}),
),
);
},
}),
() => ({
validator(_: any, value: string) {
const regex = /^[a-zA-Z0-9~!@#%^&*\-_+=|(){}[\]:;,.?/`$"<>]+$/;
if (regex.test(value)) {
return Promise.resolve();
}
return Promise.reject(
new Error(
intl.formatMessage({
id: 'OBDashboard.Cluster.New.helper.CanOnlyContainLettersNumbers',
defaultMessage:
'只能包含字母、数字和特殊字符(~!@#%^&*_-+=|(){}[]:;,.?/`$"<>)',
}),
),
);
},
}),
() => ({
validator(_: any, value: string) {
if (
/^(?=(.*[a-z]){2,})(?=(.*[A-Z]){2,})(?=(.*\d){2,})(?=(.*[~!@#%^&*_\-+=|(){}[\]:;,.?/`$'"<>\\]){2,})[A-Za-z\d~!@#%^&*_\-+=|(){}[\]:;,.?/`$'"<>\\]{2,}$/.test(
value,
)
) {
return Promise.resolve();
}
return Promise.reject(
new Error(
intl.formatMessage({
id: 'OBDashboard.Cluster.New.helper.AtLeastUppercaseAndLowercase',
defaultMessage: '大小写字母、数字和特殊字符都至少包含 2 个',
}),
),
);
},
}),
];

0 comments on commit 7fc247c

Please sign in to comment.