package com.vci.client.framework.systemConfig.stafforgmanage; import java.awt.Component; import java.util.ArrayList; import java.util.List; import com.vci.client.LogonApplication; import com.vci.client.framework.delegate.RightManagementClientDelegate; import com.vci.client.framework.systemConfig.object.CombinationObject; import com.vci.client.framework.systemConfig.object.CombinationValueObject; import com.vci.client.framework.systemConfig.object.PasswordStrategyObject; import com.vci.client.ui.exception.VCIException; import com.vci.client.ui.swing.VCIOptionPane; public class CheckPassWordStrategy { public boolean passwordStrategyCheck(String id,String password,Component dialog){ PasswordStrategyObject pwdStgObj; try { pwdStgObj = new RightManagementClientDelegate().fetchPasswordStrategyByUserId(id); if (pwdStgObj != null){ //CombinationObject[] combinationObjs = new RightManagementClientDelegate().fetchCombinationsByPstId(pwdStgObj.getId()); // String[] combinations = new RightManagementClientDelegate().fetchCombinationsByPstIdNew(pwdStgObj.getId()); int pasLen = pwdStgObj.getPasswordLen(); //最小长度 int pasMaxLen = pwdStgObj.getPasswordMaxLen();//最大长度 int requiredType = pwdStgObj.getRequiredType(); // 必填种类 int containsTypes = pwdStgObj.getCharTypes();// 包含字符类型 String names= ""; int strategy = 0; if ((containsTypes & 0x01) == 0x01) { names += "数字,"; } if ((containsTypes & 0x02) == 0x02) { names += "小写字母,"; } if ((containsTypes & 0x04) == 0x04) { names += "大写字母,"; } if ((containsTypes & 0x08) == 0x08) { names += "符号,"; } names = names.substring(0, names.length() - 1); if(password.length() < pasLen){ VCIOptionPane.showMessageDialog(dialog,"密码长度不能小于"+pasLen+",且密码必须包含‘"+names+"’中的"+requiredType+"种组合! 请重新输入密码!-1"); return false; } if(password.length() > pasMaxLen){ VCIOptionPane.showMessageDialog(dialog,"密码长度不能大于"+pasMaxLen+",且密码必须包含‘"+names+"’中的"+requiredType+"种组合! 请重新输入密码!-2"); return false; } int actualTypes = 0; String symbol = "[ _`~!@#$%^&*()-+={[}]|\\'\":;,.<>/?"; for (int i = 0 ; i < password.length() ;i ++){ char c = password.charAt(i); if (Character.isDigit(c)) actualTypes |= 0x01; else if (Character.isLowerCase(c)) actualTypes |= 0x02; else if (Character.isUpperCase(c)) actualTypes |= 0x04; else if (symbol.indexOf(c) > -1) actualTypes |= 0x08; } if ((actualTypes & containsTypes) != actualTypes){ VCIOptionPane.showMessageDialog(dialog,"您输入的密码不正确,密码必须中必须含有‘"+names+"’中的"+requiredType+"种密码组合方式,\n" + "或密码组合方式取值范围中不含有您输入的字符,请确认!-3"); return false; } int typeCount = 0; for (int i = 0; i < 4; i++) { int type = (int)Math.pow(2, i); if ((actualTypes & type) == type) typeCount++; } if (typeCount < requiredType){ VCIOptionPane.showMessageDialog(dialog,"您输入的密码不正确,密码必须中必须含有‘"+names+"’中的"+requiredType+"种密码组合方式,\n" + "或密码组合方式取值范围中不含有您输入的字符,请确认!-4"); return false; } } } catch (VCIException e) { VCIOptionPane.showError(LogonApplication.frame,"RMIPFramework", e); return false; } return true; } }