Browse Source

密码强制修改

tntdc 2 years ago
parent
commit
0a436ad28d

+ 11 - 0
adm/src/main/java/com/minpay/common/action/SystemAction.java

@@ -343,6 +343,7 @@ public class SystemAction implements IMINAction {
 		// 创建session
 		String ip = Service.lookup(ICommonService.class).getIPAddress(request);
 		User sessionUser = new User(db.selectByPrimaryKey(ImUserMapper.class, userId));
+		sessionUser.setAuthpwd(userPwd);
 		res.setSessionId(MINServiceLocator.getInstance().lookup(IMINSessionService.class).registerSession(request, sessionUser));
 		sessionUser.setLastLoginTime(lastDate);
 		sessionUser.setName(name);
@@ -432,4 +433,14 @@ public class SystemAction implements IMINAction {
 		}
 		return res;
 	}
+	
+	
+	@MINAction(value = "checkPassword", session = false)
+	public MINActionResult checkPassword(HttpServletRequest request,
+			HttpServletResponse response,
+			MINSession session) {
+		MINActionResult res = new MINActionResult();
+		res.set("MINStatus", 3);
+		return res;
+	}
 }

+ 68 - 0
adm/src/main/java/com/minpay/common/event/PasswordFilter.java

@@ -0,0 +1,68 @@
+package com.minpay.common.event;
+
+import java.io.IOException;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+
+import com.minpay.common.bean.User;
+import com.minpay.common.util.CheckPassword;
+import com.startup.minpay.frame.exception.MINBusinessException;
+import com.startup.minpay.frame.service.base.IMINSessionService;
+import com.startup.minpay.frame.service.base.Service;
+import com.startup.minpay.frame.session.MINSession;
+
+public class PasswordFilter implements Filter {
+
+	@Override
+	public void init(FilterConfig filterConfig) throws ServletException {
+		// TODO Auto-generated method stub
+		
+	}
+
+	@Override
+	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
+			throws IOException, ServletException {
+		HttpServletRequest httpServletRequest = (HttpServletRequest)request;
+		if(httpServletRequest.getRequestURI().contains(".html") 
+				|| httpServletRequest.getRequestURI().contains(".js")
+				|| httpServletRequest.getRequestURI().contains(".css")
+				|| httpServletRequest.getRequestURI().contains("/PersonManageAction/updateUserPwdForce")) {
+			chain.doFilter(request, response);
+			return;
+		}
+		// TODO Auto-generated method stub
+		MINSession session = null;
+		try {
+			session = Service.lookup(IMINSessionService.class).getSession(request);
+		} catch (MINBusinessException e1) {
+			e1.printStackTrace();
+		}
+		
+		if (session != null) {
+			User user = (User)session.getUser();
+			System.out.println(user.getAuthpwd());
+			System.out.println(user.getLogonname());
+			if(CheckPassword.checkPasswordRule(user.getAuthpwd(), user.getLogonname())) {
+				chain.doFilter(request, response);
+				return;
+			} else {
+				request.getRequestDispatcher("/adm/admin/SystemAction/checkPassword").forward(request, response);
+				return;
+			}
+		}
+		chain.doFilter(request, response);
+	}
+
+	@Override
+	public void destroy() {
+		// TODO Auto-generated method stub
+		
+	}
+
+}

+ 176 - 0
adm/src/main/java/com/minpay/common/util/CheckPassword.java

@@ -0,0 +1,176 @@
+package com.minpay.common.util;
+
+import org.apache.commons.lang.StringUtils;
+
+/**
+ * 规则:
+ * 1、长度大于8,且小于20
+ * 2、不能包含用户名
+ * 3、不能包含连续3位及以上相同字母或数字
+ * 4、不能包含3个及以上字典连续字符
+ * 4、不能包含3个及以上键盘连续字符
+ * 4、数字、小写字母、大写字母、特殊字符,至少包含三种
+ */
+public class CheckPassword {
+	/**
+     * 数字
+     */
+    private static final String REG_NUMBER = ".*\\d+.*";
+    /**
+     * 小写字母
+     */
+    private static final String REG_UPPERCASE = ".*[A-Z]+.*";
+    /**
+     * 大写字母
+     */
+    private static final String REG_LOWERCASE = ".*[a-z]+.*";
+    /**
+     * 特殊符号(~!@#$%^&*()_+|<>,.?/:;'[]{}\)
+     */
+    private static final String REG_SYMBOL = ".*[~!@#$%^&*()_+|<>,.?/:;'\\[\\]{}\"]+.*";
+    /**
+     * 键盘字符表(小写)
+     * 非shift键盘字符表
+     */
+    private static final char[][] CHAR_TABLE1 = new char[][]{
+            {'1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', '\0'},
+            {'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\\'},
+            {'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', '\0', '\0'},
+            {'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/', '\0', '\0', '\0'}};
+    /**
+     * shift键盘的字符表
+     */
+    private static final char[][] CHAR_TABLE2 = new char[][]{
+            {'!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', '\0'},
+            {'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '{', '}', '|'},
+            {'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ':', '"', '\0', '\0'},
+            {'z', 'x', 'c', 'v', 'b', 'n', 'm', '<', '>', '?', '\0', '\0', '\0'}};
+ 
+    public static void main(String[] args) {
+        String password = "qazfW852";
+        System.out.println(checkPasswordRule(password, " "));
+    }
+ 
+    /**
+     * 校验密码
+     *
+     * @param password 密码
+     * @param username 用户名
+     */
+    public static boolean checkPasswordRule(String password, String username) {
+        if (StringUtils.isEmpty(password) || password.length() < 8 || password.length() > 20) {
+            System.out.println("长度小于8,或大于20");
+            return false;
+        }
+        if (password.contains(username)) {
+            System.out.println("包含用户名");
+            return false;
+        }
+        if (isContinuousChar(password)) {
+            System.out.println("包含3个及以上相同或字典连续字符");
+            return false;
+        }
+        if (isKeyBoardContinuousChar(password)) {
+            System.out.println("包含3个及以上键盘连续字符");
+            return false;
+        }
+        int i = 0;
+        if (password.matches(REG_NUMBER)) i++;
+        if (password.matches(REG_LOWERCASE)) i++;
+        if (password.matches(REG_UPPERCASE)) i++;
+        if (password.matches(REG_SYMBOL)) i++;
+        if (i < 3) {
+            System.out.println("数字、小写字母、大写字母、特殊字符,至少包含三种");
+            return false;
+        }
+        return true;
+    }
+ 
+ 
+    /**
+     * 是否包含3个及以上相同或字典连续字符
+     */
+    private static boolean isContinuousChar(String password) {
+        char[] chars = password.toCharArray();
+        for (int i = 0; i < chars.length - 2; i++) {
+            int n1 = chars[i];
+            int n2 = chars[i + 1];
+            int n3 = chars[i + 2];
+            // 判断重复字符
+            if (n1 == n2 && n1 == n3) {
+                return true;
+            }
+            // 判断连续字符: 正序 + 倒序
+            if ((n1 + 1 == n2 && n1 + 2 == n3) || (n1 - 1 == n2 && n1 - 2 == n3)) {
+                return true;
+            }
+        }
+        return false;
+    }
+ 
+    /**
+     * 是否包含3个及以上键盘连续字符
+     *
+     * @param password 待匹配的字符串
+     */
+    private static boolean isKeyBoardContinuousChar(String password) {
+        if (StringUtils.isEmpty(password)) {
+            return false;
+        }
+        //考虑大小写,都转换成小写字母
+        char[] lpStrChars = password.toLowerCase().toCharArray();
+ 
+        // 获取字符串长度
+        int nStrLen = lpStrChars.length;
+        // 定义位置数组:row - 行,col - column 列
+        int[] pRowCharPos = new int[nStrLen];
+        int[] pColCharPos = new int[nStrLen];
+        for (int i = 0; i < nStrLen; i++) {
+            char chLower = lpStrChars[i];
+            pColCharPos[i] = -1;
+            // 检索在表1中的位置,构建位置数组
+            for (int nRowTable1Idx = 0; nRowTable1Idx < 4; nRowTable1Idx++) {
+                for (int nColTable1Idx = 0; nColTable1Idx < 13; nColTable1Idx++) {
+                    if (chLower == CHAR_TABLE1[nRowTable1Idx][nColTable1Idx]) {
+                        pRowCharPos[i] = nRowTable1Idx;
+                        pColCharPos[i] = nColTable1Idx;
+                    }
+                }
+            }
+            // 在表1中没找到,到表二中去找,找到则continue
+            if (pColCharPos[i] >= 0) {
+                continue;
+            }
+            // 检索在表2中的位置,构建位置数组
+            for (int nRowTable2Idx = 0; nRowTable2Idx < 4; nRowTable2Idx++) {
+                for (int nColTable2Idx = 0; nColTable2Idx < 13; nColTable2Idx++) {
+                    if (chLower == CHAR_TABLE2[nRowTable2Idx][nColTable2Idx]) {
+                        pRowCharPos[i] = nRowTable2Idx;
+                        pColCharPos[i] = nColTable2Idx;
+                    }
+                }
+            }
+        }
+ 
+        // 匹配坐标连线
+        for (int j = 1; j <= nStrLen - 2; j++) {
+            //同一行
+            if (pRowCharPos[j - 1] == pRowCharPos[j] && pRowCharPos[j] == pRowCharPos[j + 1]) {
+                // 键盘行正向连续(asd)或者键盘行反向连续(dsa)
+                if ((pColCharPos[j - 1] + 1 == pColCharPos[j] && pColCharPos[j] + 1 == pColCharPos[j + 1]) ||
+                        (pColCharPos[j + 1] + 1 == pColCharPos[j] && pColCharPos[j] + 1 == pColCharPos[j - 1])) {
+                    return true;
+                }
+            }
+            //同一列
+            if (pColCharPos[j - 1] == pColCharPos[j] && pColCharPos[j] == pColCharPos[j + 1]) {
+                //键盘列连续(qaz)或者键盘列反向连续(zaq)
+                if ((pRowCharPos[j - 1] + 1 == pRowCharPos[j] && pRowCharPos[j] + 1 == pRowCharPos[j + 1]) ||
+                        (pRowCharPos[j - 1] - 1 == pRowCharPos[j] && pRowCharPos[j] - 1 == pRowCharPos[j + 1])) {
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+}

+ 66 - 1
adm/src/main/java/com/minpay/guomao/personmanage/action/PersonManageAction.java

@@ -1,16 +1,21 @@
 package com.minpay.guomao.personmanage.action;
 
+import javax.servlet.http.HttpServletRequest;
+
 import org.apache.commons.lang.StringUtils;
 import com.min.sha1.SHA1;
 import com.minpay.common.bean.User;
 import com.minpay.common.service.ILogService;
+import com.minpay.common.util.CheckPassword;
 import com.minpay.common.util.RegexUtil;
 import com.minpay.db.table.mapper.ImUserMapper;
 import com.minpay.db.table.model.ImUser;
 import com.startup.minpay.frame.business.IMINAction;
 import com.startup.minpay.frame.business.res.MINActionResult;
 import com.startup.minpay.frame.exception.MINBusinessException;
+import com.startup.minpay.frame.service.MINServiceLocator;
 import com.startup.minpay.frame.service.base.IMINDataBaseService;
+import com.startup.minpay.frame.service.base.IMINSessionService;
 import com.startup.minpay.frame.service.base.Service;
 import com.startup.minpay.frame.session.MINSession;
 import com.startup.minpay.frame.target.MINAction;
@@ -35,6 +40,9 @@ public class PersonManageAction implements IMINAction {
 	/** 修改当前用户密码  */
 	public final static String	UPDATE_USER_PASSWORD		= "updateUserPwd";
 	
+	/** 修改当前用户密码  */
+	public final static String	UPDATE_USER_PASSWORD_FORCE		= "updateUserPwdForce";
+	
 	/**获取session值*/
 	public final static String GET_SESSION_INFO = "getSessionInfo";
 	
@@ -131,7 +139,8 @@ public class PersonManageAction implements IMINAction {
 			@MINParam(key = "oldPassword") String oldPassword,
 			@MINParam(key = "newPassword") String newPassword,
 			@MINParam(key = "confirmPassword") String confirmPassword,
-			MINSession session) throws MINBusinessException {
+			MINSession session,
+			HttpServletRequest request) throws MINBusinessException {
 		
 		MINActionResult res = new MINActionResult();
 		
@@ -147,6 +156,52 @@ public class PersonManageAction implements IMINAction {
 			throw new MINBusinessException("旧密码输入的不正确!");
 		}
 		
+		User user = session.getUser();
+		if(!CheckPassword.checkPasswordRule(newPassword, user.getLogonname())) {
+			throw new MINBusinessException("密码不满足条件!");
+		}
+		
+		// 加密后新密码
+		String newPad = SHA1.enCoded(session.getUser().getId().concat(newPassword));
+		imUser.setPwd(newPad);
+		// 更新基本信息
+		Service.lookup(IMINDataBaseService.class).updateByPrimaryKeySelective(ImUserMapper.class, imUser);
+		
+		// 记录操作日志
+		String logInfo = "更新密码!";
+		Service.lookup(ILogService.class).logging(session, logInfo);
+		
+		try {
+			//处理正常状态
+			if( session != null ){
+				MINServiceLocator.getInstance()
+				.lookup(IMINSessionService.class)
+				.unRegisterSession(request, session);
+			}
+		} catch (Exception ex){
+			
+		}
+		return res;
+	}
+	
+	@MINAction(value = UPDATE_USER_PASSWORD_FORCE)
+	public MINActionResult updateUserPwdForce (
+			@MINParam(key = "newPassword") String newPassword,
+			@MINParam(key = "confirmPassword") String confirmPassword,
+			MINSession session,
+			HttpServletRequest request) throws MINBusinessException {
+		MINActionResult res = new MINActionResult();
+		if(!newPassword.equals(confirmPassword)) {
+			throw new MINBusinessException("两次输入的密码不一致!");
+		}
+		
+		User user = session.getUser();
+		if(!CheckPassword.checkPasswordRule(newPassword, user.getLogonname())) {
+			throw new MINBusinessException("密码不满足条件!");
+		}
+		
+		ImUser imUser = Service.lookup(IMINDataBaseService.class).selectByPrimaryKey(ImUserMapper.class, session.getUser().getId());
+		
 		// 加密后新密码
 		String newPad = SHA1.enCoded(session.getUser().getId().concat(newPassword));
 		imUser.setPwd(newPad);
@@ -157,6 +212,16 @@ public class PersonManageAction implements IMINAction {
 		String logInfo = "更新密码!";
 		Service.lookup(ILogService.class).logging(session, logInfo);
 		
+		try {
+			//处理正常状态
+			if( session != null ){
+				MINServiceLocator.getInstance()
+				.lookup(IMINSessionService.class)
+				.unRegisterSession(request, session);
+			}
+		} catch (Exception ex){
+			
+		}
 		return res;
 	}
 	

+ 14 - 3
adm/src/main/java/com/minpay/guomao/transManage/TransManageAction.java

@@ -470,7 +470,12 @@ public class TransManageAction implements IMINAction{
 		//{"GUID":"17d342743c474a1ca22c7e56e5ed3337","RETURN":[{"STATUS":"S","MESSAGE":" [采购订单创建成功] [订单审批成功] [订单收货成功]","Z_DSPY_NO":"DC22-0607-WXGL01","EBELN":4500010225}]}
 		JSONObject resultJson = JSONObject.fromObject(result);
 		//SAP销售订单号
-		net.sf.json.JSONArray returnObject = resultJson.getJSONArray("RETURN");
+		net.sf.json.JSONArray returnObject = null;
+		try {
+			returnObject = resultJson.getJSONArray("RETURN");
+		} catch (Exception e) {
+			throw new MINBusinessException(resultJson.toString());
+		}
 		
 		//获取订单信息
 		ApOrderInf orderInfo = Service.lookup(IMINDataBaseService.class).getMybatisMapper(ApOrderInfMapper.class).selectByPrimaryKey(orderId);
@@ -672,8 +677,14 @@ public class TransManageAction implements IMINAction{
 		System.out.println("result:======"+result);
 		//{"GUID":"142d8a14bd2c43cda8e037e0d492c14b","RETURN":[{"STATUS":"S","MESSAGE":" [销售订单创建成功]","Z_DSPY_NO":"DX22-1107-TK01","VBELN":"0020003034"}]}
 		JSONObject resultJson = JSONObject.fromObject(result);
-		//SAP销售订单号
-		net.sf.json.JSONArray returnObject = resultJson.getJSONArray("RETURN");
+		net.sf.json.JSONArray returnObject = null;
+		try {
+			//SAP销售订单号
+			returnObject = resultJson.getJSONArray("RETURN");
+		} catch(Exception e) {
+			throw new MINBusinessException(returnObject.toString());
+		}
+		
 		//获取订单信息
 		ApOrderInf orderInfo = Service.lookup(IMINDataBaseService.class).getMybatisMapper(ApOrderInfMapper.class).selectByPrimaryKey(orderId);
 		//获取ERP单号

+ 8 - 0
adm/src/main/webapp/WEB-INF/web.xml

@@ -38,6 +38,14 @@
     <filter-name>SSOFilter</filter-name>
     <url-pattern>/*</url-pattern>
   </filter-mapping>
+  <filter>
+    <filter-name>PasswordFilter</filter-name>
+    <filter-class>com.minpay.common.event.PasswordFilter</filter-class>
+  </filter>
+  <filter-mapping>
+    <filter-name>PasswordFilter</filter-name>
+    <url-pattern>/*</url-pattern>
+  </filter-mapping>
   
   
   	<!-- druid 监控 -->

+ 91 - 0
adm/src/main/webapp/admin/changePwd.html

@@ -0,0 +1,91 @@
+<!DOCTYPE html>
+<html>
+
+<head>
+    <meta charset="utf-8">
+    <title>修改密码</title>
+    <meta name="renderer" content="webkit">
+    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
+    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
+    <style type="text/css">
+    	.layui-nav-img-per{width:80px;height:80px;margin-right:10px;border-radius:50%}
+    	
+		.layui-form-label {
+		    width: 70px !important;
+		}
+		.bodyClass {
+			padding: 50px;
+		}
+    </style>
+</head>
+
+<body>
+	<div class="bodyClass">
+		<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
+		  <legend>密码修改</legend>
+		</fieldset>
+		<blockquote class="layui-elem-quote layui-text">
+		  <p>1、长度大于8,且小于20</p>
+		  <p>2、不能包含用户名</p>
+		  <p>3、不能包含连续3位及以上相同字母或数字,不能包含3个及以上键盘连续字符</p>
+		  <p>4、数字、小写字母、大写字母、特殊字符,至少包含三种</p>
+		</blockquote>
+		<form class="layui-form" action="" style="margin-top: 20px;">
+	        <div class="layui-form-item">
+		         <div class="layui-inline">
+		            <label class="layui-form-label">新密码:</label>
+			            <div class="layui-input-block">
+			                <input type="password"  placeholder="请输入新密码"  name="newPassword" id="newPassword" autocomplete="off"  maxlength="20" lay-verify="newpass"  class="layui-input">
+			            </div>
+		       </div>
+	       </div>
+	        <div class="layui-form-item">
+		         <div class="layui-inline">
+		            <label class="layui-form-label">确认密码:</label>
+			            <div class="layui-input-block">
+			                <input type="password"  placeholder="请输入确认密码"  name="confirmPassword" id="confirmPassword" autocomplete="off"  maxlength="20" lay-verify="confirmPass"  class="layui-input">
+			            </div>
+		        </div>
+	       </div>
+	        <div class="layui-form-item">
+	            <div class="layui-input-block">
+	                <button class="layui-btn" lay-submit="" lay-filter="demo1">确认修改</button>
+	            </div>
+	        </div>
+	    </form>
+	</div>
+    <script src="../js/min-loader.js"></script>
+    <script>
+    layui.use(['form', 'layedit', 'laydate', 'upload'], function() {
+            var form = layui.form,
+                layer = layui.layer,
+                layedit = layui.layedit;
+    		//监听提交
+            form.on('submit(demo1)', function(data) {
+            	// 两次输入的新密码不一致!
+            	if(data.field.confirmPassword != data.field.newPassword) {
+            		$.ErrorAlert('两次输入的新密码不一致!');
+            		return false;
+            	}
+               $.request({
+					action : 'PersonManageAction/updateUserPwdForce',
+					data :  data.field ,
+					success : function(data) {
+						$.Alert('密码修改成功,请重新登录!');
+						setTimeout('top.location.href = "http://'+ window.location.host +getContextPath() + loginUrl +'"', 3000);
+					},
+					error : function(data) {
+						$.ErrorAlert(data.msg);
+					}
+				});	
+                return false;
+            });
+    
+      });
+    
+ 
+    </script>
+
+</body>
+
+</html>

+ 0 - 19
adm/src/main/webapp/admin/login.html

@@ -67,31 +67,12 @@
 
   <script>
   
-   function checkMsg(){
-		// 检查是否需要短信验证码
-	  	$.request({
-				action : "SystemAction/isCheckSMS",
-				loading : false,
-				success : function(data) {
-					if(data.isCheckSms == 'true'){
-						$('#smdMsg').show();
-					}
-					else {
-						$('#smdMsg').hide();
-					}
-				},
-				error : function(data) {
-				}
-		});
-   }
-   
     layui.use(['layer', 'form'], function() {
      
        var form = layui.form,
         $ = layui.jquery;
        $('#smdMsg').hide();
        // 检查短信验证码
-       checkMsg();
        
       $('#forgot').on('click', function() {
         layer.msg('请联系管理员.');

+ 8 - 2
adm/src/main/webapp/js/min.js

@@ -124,8 +124,14 @@ $.request = function(options) {
 					}
 				}
 				else if (obj.MINStatus == "2") {//登录超时
-					$.Alert("登录超时,3秒后跳到登录页面", "登录超时");
-					setTimeout('top.location.href = "' + protocolStr + window.location.host +getContextPath() + loginUrl +'"', 3000);
+					if(!top.location.href.includes(loginUrl)) {
+						$.Alert("登录超时,3秒后跳到登录页面", "登录超时");
+						setTimeout('top.location.href = "' + protocolStr + window.location.host +getContextPath() + loginUrl +'"', 3000);
+					}
+				}else if (obj.MINStatus == "3") {//强制修改密码
+					if(!top.location.href.includes("/admin/changePwd.html")) {
+						setTimeout('top.location.href = "' + protocolStr + window.location.host +getContextPath() + "/admin/changePwd.html" +'"', 1000);
+					}
 				}
 			}else if(statusTxt == "error"){
 				$.Alert(xhr.status + ":" + xhr.statusText);