package com.vci.client.logon.base;
|
|
import com.vci.client.framework.systemConfig.object.PasswordStrategyObject;
|
|
/**
|
* <p>Title: 获取密码级别</p>
|
* <p>Description: 通过checkStrong方法获取输入密码的基本,现阶段系统提供5个级别:
|
* 0代表密码长度太短不符合要求,1和2代表初级、3代表中级、4代表高级</p>
|
* <p>Copyright: Copyright (c) 2011</p>
|
* <p>Company: VCI</p>
|
* @author Administrator
|
* @time 2011-8-18
|
* @version 1.0
|
*/
|
public class PasswordLevel {
|
|
/**
|
* 获取字符串每个字符的类型
|
* <p>Description: </p>
|
*
|
* @author Administrator
|
* @time 2011-8-18
|
* @param sChar
|
* @return
|
*/
|
public static int charMode(char sChar) {
|
if (sChar >= 48 && sChar <= 57) {//数字
|
return 1;
|
} else if (sChar >= 65 && sChar <= 90) {//大写字母
|
return 2;
|
} else if (sChar >= 97 && sChar <= 122) {//小写
|
return 4;
|
} else {
|
return 8; //特殊字符
|
}
|
}
|
|
/**
|
* 计算出当前密码当中一共有多少种模式
|
*
|
* <p>Description: </p>
|
*
|
* @author Administrator
|
* @time 2011-8-18
|
* @param num
|
* @return
|
*/
|
public static int bitTotal(int num) {
|
int modes = 0;
|
for (int i = 0; i < 4; i++){
|
int mid = num & 1;
|
if (mid > 0) {
|
modes++;
|
}
|
num >>>= 1;
|
}
|
return modes;
|
}
|
|
public static int checkStrong(String sPW ,Object object){
|
if (sPW.length() < ((PasswordStrategyObject)object).getPasswordLen()) {
|
return 0;
|
}
|
int Modes = 0;
|
for (int i = 0; i < sPW.length(); i++){
|
Modes |= charMode(sPW.charAt(i));
|
}
|
return bitTotal(Modes);
|
}
|
}
|