Commit 8252d329 authored by 杨思琦's avatar 杨思琦

fix: 弱口令检测

parent 7b6f465f
Pipeline #60930 waiting for manual action with stages
...@@ -16,61 +16,65 @@ const formItemLayout = { ...@@ -16,61 +16,65 @@ const formItemLayout = {
* 云平台上判断是否是默认密码 * 云平台上判断是否是默认密码
* 如果是默认密码,强制要求修改密码 * 如果是默认密码,强制要求修改密码
*/ */
let info = '666';
let infoPre = 'panda';
const ValidContainer = props => { const ValidContainer = props => {
const [needChangePassword, setNeedChangePassword] = useState(false); const [needChangePassword, setNeedChangePassword] = useState(false);
const [form] = Form.useForm(); const [form] = Form.useForm();
// eslint-disable-next-line react/no-this-in-sfc
const password = localStorage.getItem('password_token');
let rules = localStorage.getItem('password_pwdRegex');
const rulesTip = localStorage.getItem('password_pwdRegexTip');
let reg;
try {
reg = new RegExp(rules);
} catch (error) {
rules = '';
reg = new RegExp(rules);
}
useEffect(() => { useEffect(() => {
if (window.location.origin.replace(/^(http|https):\/\//, '') !== 'panda-water.cn') return; // if (window.location.origin.replace(/^(http|https):\/\//, '') !== 'panda-water.cn') return;
const { global } = props; const { global } = props;
const tk = global.token; const tk = global.token;
// eslint-disable-next-line no-eval
if (tk) { if (tk) {
appService.validDefaultPWD({ if (rules !== '' && !reg.test(password)) {
ignoreSite: true, setNeedChangePassword(true);
token: tk
}).then(res => {
if(res.code === 0) {
const { data } = res;
setNeedChangePassword(data.valid);
info = data.info;
} }
}).catch(err => {
})
} }
}, []); }, []);
const handleOK = (e) => { const handleOK = e => {
e.stopPropagation(); e.stopPropagation();
form form
.validateFields() .validateFields()
.then((res) => { .then(res => {
const params = { const params = {
password: `${infoPre}${info}`, // 拼接默认密码 password, // 拼接默认密码
newpassword: res.newPwd, newpassword: res.newPwd,
token: window.globalConfig.token, token: window.globalConfig.token,
ignoreSite: true, ignoreSite: true,
} };
appService appService
.changePassword(params) .changePassword(params)
.then((res) => { // eslint-disable-next-line no-shadow
.then(res => {
if (res.success) { if (res.success) {
message.success(globalHeader['component.account.password.update.success']); message.success(globalHeader['component.account.password.update.success']);
setTimeout(() => { setTimeout(() => {
// setNeedChangePassword(false); setNeedChangePassword(false);
props.logout(); // props.logout();
}, 300); }, 300);
} else { } else {
message.error(globalHeader['component.account.oldpassword.errorMessage']); message.error(globalHeader['component.account.oldpassword.errorMessage']);
} }
}) })
.catch((error) => { .catch(error => {
message.error(globalHeader['component.account.password.update.fail']); message.error(globalHeader['component.account.password.update.fail']);
}); });
}).catch((error) => { })
console.log(error) .catch(error => {
console.log(error);
}); });
} };
return ( return (
<> <>
{props.children} {props.children}
...@@ -87,7 +91,7 @@ const ValidContainer = props => { ...@@ -87,7 +91,7 @@ const ValidContainer = props => {
// zIndex={2000} // zIndex={2000}
> >
<div className={styles['info-label']}> <div className={styles['info-label']}>
<ExclamationCircleFilled style={{color: '#FCAC0F', fontSize: '16px'}}/> <ExclamationCircleFilled style={{ color: '#FCAC0F', fontSize: '16px' }} />
<span>用户首次登录之前必须修改密码</span> <span>用户首次登录之前必须修改密码</span>
</div> </div>
<Form labelAlign="left" {...formItemLayout} form={form}> <Form labelAlign="left" {...formItemLayout} form={form}>
...@@ -100,16 +104,9 @@ const ValidContainer = props => { ...@@ -100,16 +104,9 @@ const ValidContainer = props => {
message: '请输入新密码', message: '请输入新密码',
}, },
{ {
pattern: /^(?![0-9]+$)(?![a-zA-Z]+$)[a-zA-Z0-9_]{8,16}$/, pattern: reg,
message: '密码需为8-16个数字、字符和下划线', message: rulesTip,
}, },
({ getFieldValue }) => ({
validator(rule, value) {
if(value === `${infoPre}${props?.global?.userInfo?.loginName ?? info}` || value === 'panda666')
return Promise.reject('密码规则不允许');
return Promise.resolve();
},
})
]} ]}
hasFeedback hasFeedback
> >
...@@ -127,13 +124,13 @@ const ValidContainer = props => { ...@@ -127,13 +124,13 @@ const ValidContainer = props => {
}, },
({ getFieldValue }) => ({ ({ getFieldValue }) => ({
validator(rule, value) { validator(rule, value) {
if (!/^(?![0-9]+$)(?![a-zA-Z]+$)[a-zA-Z0-9_]{8,16}$/.test(value)) if (!reg.test(value))
return Promise.reject('密码需为8-16个数字、字符和下划线'); // eslint-disable-next-line prefer-promise-reject-errors
if (value === `${infoPre}${props?.global?.userInfo?.loginName ?? info}` || value === 'panda666') return Promise.reject(rulesTip);
return Promise.reject('密码规则不允许');
if (!value || getFieldValue('newPwd') === value) { if (!value || getFieldValue('newPwd') === value) {
return Promise.resolve(); return Promise.resolve();
} }
// eslint-disable-next-line prefer-promise-reject-errors
return Promise.reject('确认密码与新密码输入不一致'); return Promise.reject('确认密码与新密码输入不一致');
}, },
}), }),
......
...@@ -41,7 +41,16 @@ class AvatarDropdown extends React.Component { ...@@ -41,7 +41,16 @@ class AvatarDropdown extends React.Component {
popVisible: false, popVisible: false,
path: null, path: null,
action: API.UPLOAD_FILE_URL, action: API.UPLOAD_FILE_URL,
rulesTip: localStorage.getItem('password_pwdRegexTip'),
reg: ''
}; };
let rules = localStorage.getItem('password_pwdRegex');
try {
this.state.reg = new RegExp(rules);
} catch (error) {
rules = '';
this.state.reg = new RegExp(rules);
}
} }
loginout = (event) => { loginout = (event) => {
// eslint-disable-next-line no-undef // eslint-disable-next-line no-undef
...@@ -424,8 +433,8 @@ class AvatarDropdown extends React.Component { ...@@ -424,8 +433,8 @@ class AvatarDropdown extends React.Component {
message: '请输入新密码', message: '请输入新密码',
}, },
{ {
pattern: /^(?![0-9]+$)(?![a-zA-Z]+$)[a-zA-Z0-9!@#$%^&*_]{8,16}$/, pattern: this.state.reg,
message: '密码字符长度为8-16个字符', message: this.state.rulesTip,
}, },
]} ]}
hasFeedback hasFeedback
......
This diff is collapsed.
This diff is collapsed.
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