fix checkpassword

This commit is contained in:
bwcx_jzy 2022-08-14 15:33:24 +08:00
parent 9e6edb150e
commit 305ebb755b
No known key found for this signature in database
GPG Key ID: 5E48E9372088B9E5
2 changed files with 23 additions and 89 deletions

View File

@ -22,14 +22,18 @@
*/
package io.jpom.system.init;
import cn.hutool.core.text.PasswdStrength;
import cn.hutool.core.util.StrUtil;
import cn.jiangzeyin.common.PreLoadClass;
import cn.jiangzeyin.common.PreLoadMethod;
import io.jpom.JpomApplication;
import io.jpom.system.JpomRuntimeException;
import io.jpom.system.ServerExtConfigBean;
import io.jpom.util.CheckPassword;
import lombok.extern.slf4j.Slf4j;
import static cn.hutool.core.text.PasswdStrength.PASSWD_LEVEL.EASY;
import static cn.hutool.core.text.PasswdStrength.PASSWD_LEVEL.MIDIUM;
/**
* 验证token 合法性
*
@ -40,20 +44,22 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j
public class CheckAuthorizeToken {
@PreLoadMethod
private static void check() {
String authorizeToken = ServerExtConfigBean.getInstance().getAuthorizeToken();
if (StrUtil.isEmpty(authorizeToken)) {
return;
}
if (authorizeToken.length() < 6) {
log.error("配置的授权token长度小于六位不生效", new JpomRuntimeException("配置的授权token长度小于六位不生效"));
System.exit(-1);
}
int strength = CheckPassword.checkPasswordStrength(authorizeToken);
if (strength != 2) {
log.error("配置的授权token 需要包含数字,字母,符号的组合", new JpomRuntimeException("配置的授权token 需要包含数字,字母,符号的组合"));
System.exit(-1);
}
}
@PreLoadMethod
private static void check() {
String authorizeToken = ServerExtConfigBean.getInstance().getAuthorizeToken();
if (StrUtil.isEmpty(authorizeToken)) {
return;
}
if (authorizeToken.length() < 6) {
log.error("配置的授权token长度小于六位不生效", new JpomRuntimeException("配置的授权token长度小于六位不生效"));
System.exit(-1);
}
PasswdStrength.PASSWD_LEVEL level = PasswdStrength.getLevel(authorizeToken);
if (level == EASY || level == MIDIUM) {
JpomApplication.consoleExit(-1, "配置的授权token 需要包含数字,字母,符号的组合");
//log.error("配置的授权token 需要包含数字,字母,符号的组合", new JpomRuntimeException("配置的授权token 需要包含数字,字母,符号的组合"));
//System.exit(-1);
}
}
}

View File

@ -1,72 +0,0 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Code Technology Studio
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package io.jpom.util;
/**
* 判断密码强度
*
* @author jiangzeyin
* @since 2019/3/18
*/
public class CheckPassword {
private static final String REGEX_Z = "\\d*";
private static final String REGEX_S = "[a-zA-Z]+";
private static final String REGEX_T = "\\W+$";
private static final String REGEX_ZT = "\\D*";
private static final String REGEX_ST = "[\\d\\W]*";
private static final String REGEX_ZS = "\\w*";
private static final String REGEX_ZST = "[\\w\\W]*";
/**
* 密码强度
* Z = 字母 S = 数字 T = 特殊字符
*
* @param passwordStr 密码字符串
* @return 0 1 2强
*/
public static int checkPasswordStrength(String passwordStr) {
if (passwordStr.matches(REGEX_Z)) {
return 0;
}
if (passwordStr.matches(REGEX_S)) {
return 0;
}
if (passwordStr.matches(REGEX_T)) {
return 0;
}
if (passwordStr.matches(REGEX_ZT)) {
return 1;
}
if (passwordStr.matches(REGEX_ST)) {
return 1;
}
if (passwordStr.matches(REGEX_ZS)) {
return 1;
}
if (passwordStr.matches(REGEX_ZST)) {
return 2;
}
return -1;
}
}