wangting
2024-12-26 fa261e8c1220b31af54e8167e4de9c3320b1af27
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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); 
    }
}