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

fix: 弱口令检测

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