java弱口令检测机制解析

时间:2022-09-22 20:35:28

java弱口令检测机制

1. 设计要求

  • 应具备检测口令的长度和是否在指定字符集合内的能力。
  • 应具备检测口令字符逻辑相邻的能力,如aBc,abC等。
  • 应具备检测口令字符键盘物理位置相邻的能力,包括横向和左右斜线方向的相邻,如qwer 1qaz 0okm等。
  • 应具备检测口令是否出现在弱口令库中的能力。
  • 应具备检测口令中是否包含用户名(不区分大小写)。
  • 应具备相邻单字符多次重复检测。

2. 二级系统配置要求

  • 口令应为字母(区分大小写)+数字的组合,长度不小于8位,数字个数必须大于等于1,小写或大写字母个数大于等于1。
  • 口令字符在键盘物理位置上横向不允许有连续4个及以上的相邻,物理横向字符集包含“qwertyuiop asdfghjkl zxcvbnm 01234567890”。
  • 口令中的字符在键盘物理位置上斜线方向不允许有连续4个及以上的相邻,物理斜线方向字符集包含“1qaz 2wsx 3edc 4rfv 5tgb 6yhn 7ujm 8ik, 9ol. 0p;/ =[;. -pl, 0okm 9ijn 8uhb 7ygv 6tfc 5rdx 4esz”。
  • 口令中的字符在逻辑位置上不允许有连续4个及以上相邻,例如abcd,1234等,必须是严格意义上的逻辑相邻abcD、aBcd、Abcd也属于逻辑相邻;逻辑字符集为“abcdefghijklmnopqrstuvwxyz 0123456789”。
  • 相邻单字符重复次数不得超过4次。

3. 三级系统配置要求

  • 口令应为英文字母(区分大小写)+数字+特殊字符三者的组合,长度不小于8位;数字个数必须大于等于1,小写或大写字母个数大于等于1,特殊字符个数大于等于1。
  • 口令中的字符在键盘物理位置上横向不允许有连续3个及以上相邻,物理横向字符集包含“qwertyuiop asdfghjkl zxcvbnm 01234567890”。
  • 口令中字符在键盘物理位置上斜线方向不允许有连续3个及以上相邻,物理斜线方向字符集包含“1qaz 2wsx 3edc 4rfv 5tgb 6yhn 7ujm 8ik, 9ol. 0p;/ =[;.、-pl,、0okm、9ijn、8uhb、7ygv 6tfc、5rdx 4esz”。
  • 口令中字符在逻辑位置上不允许有连续3个及以上相邻的,例如abc,123等,必须是严格意义上的逻辑相邻abC、aBc、Abc也属于逻辑相邻;逻辑字符集为“abcdefghijklmnopqrstuvwxyz 0123456789”。
  • 口令中的特殊字符集为“!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~” 不包含两边引号共32位字符。
  • 相邻单字符重复次数不得超过3次。

4. java编码

?
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
package com.security.weakpassword;
import java.lang.String;
public class CheckPWD {
    /**
     * @brief   检测密码中字符长度
     * @param[in] password            密码字符串
     * @return  符合长度要求 返回true
     */
    public static boolean checkPasswordLength(String password) {
        boolean flag =false;
 
        if("".equals(config.MAX_LENGTH)) {
            if (password.length() >= Integer.parseInt(config.MIN_LENGTH)) {
                flag = true;
            }
        }else{
            if (password.length() >= Integer.parseInt(config.MIN_LENGTH) &&
                    password.length() <= Integer.parseInt(config.MAX_LENGTH)) {
                flag = true;
            }
        }
        return flag;
    }
 
    /**
     * @brief   检测密码中是否包含数字
     * @param[in] password            密码字符串
     * @return  包含数字 返回true
     */
    public static boolean checkContainDigit(String password) {
        char[] chPass = password.toCharArray();
        boolean flag = false;
        int num_count = 0;
 
        for (int i = 0; i < chPass.length; i++) {
            if (Character.isDigit(chPass[i])) {
                num_count++;
            }
        }
 
        if (num_count >= 1){
            flag = true;
        }
        return flag;
    }
 
    /**
     * @brief   检测密码中是否包含字母(不区分大小写)
     * @param[in] password            密码字符串
     * @return  包含字母 返回true
     */
    public static boolean checkContainCase(String password) {
        char[] chPass = password.toCharArray();
        boolean flag = false;
        int char_count = 0;
 
        for (int i = 0; i < chPass.length; i++) {
            if (Character.isLetter(chPass[i])) {
                char_count++;
            }
        }
 
        if (char_count >= 1) {
            flag = true;
        }
        return flag;
    }
 
    /**
     * @brief   检测密码中是否包含小写字母
     * @param[in] password            密码字符串
     * @return  包含小写字母 返回true
     */
    public static boolean checkContainLowerCase(String password) {
        char[] chPass = password.toCharArray();
        boolean flag = false;
        int char_count = 0;
 
        for (int i = 0; i < chPass.length; i++) {
            if (Character.isLowerCase(chPass[i])) {
                char_count++;
            }
        }
 
        if (char_count >= 1) {
            flag = true;
        }
        return flag;
    }
 
    /**
     * @brief   检测密码中是否包含大写字母
     * @param[in] password            密码字符串
     * @return  包含大写字母 返回true
     */
    public static boolean checkContainUpperCase(String password) {
        char[] chPass = password.toCharArray();
        boolean flag = false;
        int char_count = 0;
 
        for (int i = 0; i < chPass.length; i++) {
            if (Character.isUpperCase(chPass[i])) {
                char_count++;
            }
        }
 
        if (char_count >= 1) {
            flag = true;
        }
        return flag;
    }
 
    /**
     * @brief   检测密码中是否包含特殊符号
     * @param[in] password            密码字符串
     * @return  包含特殊符号 返回true
     */
    public static boolean checkContainSpecialChar(String password) {
        char[] chPass = password.toCharArray();
        boolean flag = false;
        int special_count = 0;
 
        for (int i = 0; i < chPass.length; i++) {
            if (config.SPECIAL_CHAR.indexOf(chPass[i]) != -1) {
                special_count++;
            }
        }
 
        if (special_count >= 1){
            flag = true;
        }
        return flag;
    }
 
    /**
     * @brief   键盘规则匹配器 横向连续检测
     * @param[in] password            密码字符串
     * @return  含有横向连续字符串 返回true
     */
    public static boolean checkLateralKeyboardSite(String password) {
        String t_password = new String(password);
        //将所有输入字符转为小写
        t_password = t_password.toLowerCase();
        int n = t_password.length();
        /**
         * 键盘横向规则检测
         */
        boolean flag = false;
        int arrLen = config.KEYBOARD_HORIZONTAL_ARR.length;
        int limit_num = Integer.parseInt(config.LIMIT_HORIZONTAL_NUM_KEY) ;
 
        for(int i=0; i+limit_num<=n; i++) {
            String str = t_password.substring(i, i+limit_num);
            String distinguishStr = password.substring(i, i+limit_num);
 
            for(int j=0; j<arrLen; j++) {
                String configStr = config.KEYBOARD_HORIZONTAL_ARR[j];
                String revOrderStr = new StringBuffer(config.KEYBOARD_HORIZONTAL_ARR[j]).reverse().toString();
 
                //检测包含字母(区分大小写)
                if ("enable".equals(config.CHECK_DISTINGGUISH_CASE)) {
                    //考虑 大写键盘匹配的情况
                    String UpperStr = config.KEYBOARD_HORIZONTAL_ARR[j].toUpperCase();
                    if((configStr.indexOf(distinguishStr) != -1) || (UpperStr.indexOf(distinguishStr) != -1)) {
                        flag = true;
                        return flag;
                    }
                    //考虑逆序输入情况下 连续输入
                    String revUpperStr = new StringBuffer(UpperStr).reverse().toString();
                    if((revOrderStr.indexOf(distinguishStr) != -1) || (revUpperStr.indexOf(distinguishStr) != -1)) {
                        flag = true;
                        return flag;
                    }
                }else {
                    if(configStr.indexOf(str) != -1) {
                        flag = true;
                        return flag;
                    }
                    //考虑逆序输入情况下 连续输入
                    if(revOrderStr.indexOf(str) != -1) {
                        flag = true;
                        return flag;
                    }
                }
            }
        }
        return flag;
    }
 
    /**
     * @brief   键盘规则匹配器 斜向规则检测
     * @param[in] password            密码字符串
     * @return  含有斜向连续字符串 返回true
     */
    public static boolean checkKeyboardSlantSite(String password) {
        String t_password = new String(password);
        t_password = t_password.toLowerCase();
        int n = t_password.length();
        /**
         * 键盘斜线方向规则检测
         */
        boolean flag = false;
        int arrLen = config.KEYBOARD_SLOPE_ARR.length;
        int limit_num = Integer.parseInt(config.LIMIT_SLOPE_NUM_KEY);
 
        for(int i=0; i+limit_num<=n; i++) {
            String str = t_password.substring(i, i+limit_num);
            String distinguishStr = password.substring(i, i+limit_num);
            for(int j=0; j<arrLen; j++) {
                String configStr = config.KEYBOARD_SLOPE_ARR[j];
                String revOrderStr = new StringBuffer(config.KEYBOARD_SLOPE_ARR[j]).reverse().toString();
                //检测包含字母(区分大小写)
                if ("enable".equals(config.CHECK_DISTINGGUISH_CASE)) {
 
                    //考虑 大写键盘匹配的情况
                    String UpperStr = config.KEYBOARD_SLOPE_ARR[j].toUpperCase();
                    if((configStr.indexOf(distinguishStr) != -1) || (UpperStr.indexOf(distinguishStr) != -1)) {
                        flag = true;
                        return flag;
                    }
                    //考虑逆序输入情况下 连续输入
                    String revUpperStr = new StringBuffer(UpperStr).reverse().toString();
                    if((revOrderStr.indexOf(distinguishStr) != -1) || (revUpperStr.indexOf(distinguishStr) != -1)) {
                        flag = true;
                        return flag;
                    }
                }else {
                    if(configStr.indexOf(str) != -1) {
                        flag = true;
                        return flag;
                    }
                    //考虑逆序输入情况下 连续输入
                    if(revOrderStr.indexOf(str) != -1) {
                        flag = true;
                        return flag;
                    }
                }
            }
        }
        return flag;
    }
 
    /**
     * @brief   评估a-z,z-a这样的连续字符
     * @param[in] password            密码字符串
     * @return  含有a-z,z-a连续字符串 返回true
     */
    public static boolean checkSequentialChars(String password) {
        String t_password = new String(password);
        boolean flag = false;
        int limit_num = Integer.parseInt(config.LIMIT_LOGIC_NUM_CHAR);
        int normal_count = 0;
        int reversed_count = 0;
 
        //检测包含字母(区分大小写)
        if ("enable".equals(config.CHECK_DISTINGGUISH_CASE)) {
 
        }else{
            t_password = t_password.toLowerCase();
        }
        int n = t_password.length();
        char[] pwdCharArr = t_password.toCharArray();
 
        for (int i=0; i+limit_num<=n; i++) {
            normal_count = 0;
            reversed_count = 0;
            for (int j=0; j<limit_num-1; j++) {
                if (pwdCharArr[i+j+1]-pwdCharArr[i+j]==1) {
                    normal_count++;
                    if(normal_count == limit_num -1){
                        return true;
                    }
                }
 
                if (pwdCharArr[i+j]-pwdCharArr[i+j+1]==1) {
                    reversed_count++;
                    if(reversed_count == limit_num -1){
                        return true;
                    }
                }
            }
        }
        return flag;
    }
 
    /**
     * @brief   评估aaaa,1111这样的相同连续字符
     * @param[in] password            密码字符串
     * @return  含有aaaa,1111等连续字符串 返回true
     */
    public static boolean checkSequentialSameChars(String password) {
        String t_password = new String(password);
        int n = t_password.length();
        char[] pwdCharArr = t_password.toCharArray();
        boolean flag = false;
        int limit_num = Integer.parseInt(config.LIMIT_NUM_SAME_CHAR);
        int count = 0;
        for (int i=0; i+limit_num<=n; i++) {
            count=0;
            for (int j=0; j<limit_num-1; j++) {
                if(pwdCharArr[i+j] == pwdCharArr[i+j+1]) {
                    count++;
                    if (count == limit_num -1){
                        return true;
                    }
                }
            }
        }
        return flag;
    }
 
    /**
     * @brief   评估密码中包含的字符类型是否符合要求
     * @param[in] password            密码字符串
     * @return  符合要求 返回true
     */
    public static boolean EvalPWD(String password) {
        if (password == null || "".equals(password)) {
            return false;
        }
        boolean flag = false;
 
        /**
         * 检测长度
         */
        if ("enable".equals(config.CHECK_PASSWORD_LENGTH)){
            flag = checkPasswordLength(password);
            if (!flag) {
                return false;
            }
        }
 
        /**
         * 检测包含数字
         */
        if ("enable".equals(config.CHECK_CONTAIN_DIGIT)){
            flag = checkContainDigit(password);
            if (!flag) {
                return false;
            }
        }
 
        /**
         * 检测包含字母(区分大小写)
         */
        if ("enable".equals(config.CHECK_DISTINGGUISH_CASE)){
            //检测包含小写字母
            if ("enable".equals(config.CHECK_LOWER_CASE)){
                flag = checkContainLowerCase(password);
                if (!flag) {
                    return false;
                }
            }
 
            //检测包含大写字母
            if ("enable".equals(config.CHECK_UPPER_CASE)){
                flag = checkContainUpperCase(password);
                if (!flag) {
                    return false;
                }
            }
        }else {
            flag = checkContainCase(password);
            if (!flag) {
                return false;
            }
        }
 
        /**
         * 检测包含特殊符号
         */
        if ("enable".equals(config.CHECK_CONTAIN_SPECIAL_CHAR)){
            flag = checkContainSpecialChar(password);
            if (!flag) {
                return false;
            }
        }
 
        /**
         * 检测键盘横向连续
         */
        if ("enable".equals(config.CHECK_HORIZONTAL_KEY_SEQUENTIAL)){
            flag = checkLateralKeyboardSite(password);
            if (flag) {
                return false;
            }
        }
 
        /**
         * 检测键盘斜向连续
         */
        if ("enable".equals(config.CHECK_SLOPE_KEY_SEQUENTIAL)){
            flag = checkKeyboardSlantSite(password);
            if (flag) {
                return false;
            }
        }
 
        /**
         * 检测逻辑位置连续
         */
        if ("enable".equals(config.CHECK_LOGIC_SEQUENTIAL)){
            flag = checkSequentialChars(password);
            if (flag) {
                return false;
            }
        }
 
        /**
         * 检测相邻字符是否相同
         */
        if ("enable".equals(config.CHECK_SEQUENTIAL_CHAR_SAME)){
            flag = checkSequentialSameChars(password);
            if (flag) {
                return false;
            }
        }
        return true;
    }
}
?
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
package com.security.weakpassword;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Iterator;
import java.util.Properties;
public class config {
    /**
     * 密码口令检测对应系统等级
     */
    public static String SYSTEM_GRADE;
 
    /**
     * 是否检测密码口令长度标识
     */
    public static String CHECK_PASSWORD_LENGTH;
    /**
     * 密码最小长度,默认为8
     */
    public static String MIN_LENGTH;
    /**
     * 密码最大长度,默认为20
     */
    public static String MAX_LENGTH;
 
    /**
     * 是否包含数字
     */
    public static String CHECK_CONTAIN_DIGIT;
    /**
     * 是否区分大小写
     */
    public static String CHECK_DISTINGGUISH_CASE;
    /**
     * 是否包含小写字母
     */
    public static String CHECK_LOWER_CASE;
    /**
     * 是否包含大写字母
     */
    public static String CHECK_UPPER_CASE;
    /**
     * 是否包含特殊符号
     */
    public static String CHECK_CONTAIN_SPECIAL_CHAR;
    /**
     * 特殊符号集合
     */
    public static String DEFAULT_SPECIAL_CHAR="!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~";
    public static String SPECIAL_CHAR;
 
    /**
     * 是否检测键盘按键横向连续
     */
    public static String CHECK_HORIZONTAL_KEY_SEQUENTIAL;
    /**
     * 键盘物理位置横向不允许最小的连续个数
     */
    public static String LIMIT_HORIZONTAL_NUM_KEY;
    /**
     * 是否检测键盘按键斜向连续
     */
    public static String CHECK_SLOPE_KEY_SEQUENTIAL;
    /**
     * 键盘物理位置斜向不允许最小的连续个数
     */
    public static String LIMIT_SLOPE_NUM_KEY;
 
    /**
     * 是否检测逻辑位置连续
     */
    public static String CHECK_LOGIC_SEQUENTIAL;
    /**
     * 密码口令中字符在逻辑位置上不允许最小的连续个数
     */
    public static String LIMIT_LOGIC_NUM_CHAR;
 
    /**
     * 是否检测连续字符相同
     */
    public static String CHECK_SEQUENTIAL_CHAR_SAME;
    /**
     * 密码口令中相同字符不允许最小的连续个数
     */
    public static String LIMIT_NUM_SAME_CHAR;
 
    /**
     * 键盘横向方向规则
     */
    public static String[] KEYBOARD_HORIZONTAL_ARR = {
            "01234567890",
            "qwertyuiop",
            "asdfghjkl",
            "zxcvbnm",
    };
    /**
     * 键盘斜线方向规则
     */
    public static String[] KEYBOARD_SLOPE_ARR = {
            "1qaz",
            "2wsx",
            "3edc",
            "4rfv",
            "5tgb",
            "6yhn",
            "7ujm",
            "8ik,",
            "9ol.",
            "0p;/",
            "=[;.",
            "-pl,",
            "0okm",
            "9ijn",
            "8uhb",
            "7ygv",
            "6tfc",
            "5rdx",
            "4esz"
    };
    static {
        Properties prop = new Properties();
 
        try{
            //读取属性文件enc.properties
            InputStream in = new BufferedInputStream(new FileInputStream("password.properties"));
            prop.load(in);
            Iterator<String> it=prop.stringPropertyNames().iterator();
            while(it.hasNext()) {
                String key = it.next();
 
                if (key.equals("systemGrade")) {
                    SYSTEM_GRADE = prop.getProperty(key);
                }
 
                if (key.equals("checkPasswordLength")) {
                    CHECK_PASSWORD_LENGTH = prop.getProperty(key);
                }
                if (key.equals("limitPassMinLength")) {
                    MIN_LENGTH = prop.getProperty(key);
                }
                if (key.equals("limitPassMaxLength")) {
                    MAX_LENGTH = prop.getProperty(key);
                }
 
                if (key.equals("checkContainDigit")) {
                    CHECK_CONTAIN_DIGIT = prop.getProperty(key);
                }
                if (key.equals("checkContainUpperLowerCase")) {
                    CHECK_DISTINGGUISH_CASE = prop.getProperty(key);
                }
                if (key.equals("checkContainLowerCase")) {
                    CHECK_LOWER_CASE = prop.getProperty(key);
                }
                if (key.equals("checkContainUpperCase")) {
                    CHECK_UPPER_CASE = prop.getProperty(key);
                }
                if (key.equals("checkContainSpecialChar")) {
                    CHECK_CONTAIN_SPECIAL_CHAR = prop.getProperty(key);
                }
                if (key.equals("specialCharSet")) {
                    SPECIAL_CHAR = prop.getProperty(key);
                }
 
                if (key.equals("checkHorizontalKeySequential")) {
                    CHECK_HORIZONTAL_KEY_SEQUENTIAL = prop.getProperty(key);
                }
                if (key.equals("horizontalKeyLimitNum")) {
                    LIMIT_HORIZONTAL_NUM_KEY = prop.getProperty(key);
                }
                if (key.equals("checkSlopeKeySequential")) {
                    CHECK_SLOPE_KEY_SEQUENTIAL = prop.getProperty(key);
                }
                if (key.equals("slopeKeyLimitNum")) {
                    LIMIT_SLOPE_NUM_KEY = prop.getProperty(key);
                }
 
                if (key.equals("checkLogicSequential")) {
                    CHECK_LOGIC_SEQUENTIAL = prop.getProperty(key);
                }
                if (key.equals("logicLimitNum")) {
                    LIMIT_LOGIC_NUM_CHAR = prop.getProperty(key);
                }
 
                if (key.equals("checkSequentialCharSame")) {
                    CHECK_SEQUENTIAL_CHAR_SAME = prop.getProperty(key);
                }
                if (key.equals("sequentialCharNum")) {
                    LIMIT_NUM_SAME_CHAR = prop.getProperty(key);
                }
 
            }
            in.close();
 
            if("2".equals(SYSTEM_GRADE) || "3".equals(SYSTEM_GRADE) ) {
 
                if("".equals(CHECK_PASSWORD_LENGTH)){
                    CHECK_PASSWORD_LENGTH = "enable";
                    MIN_LENGTH = "8";
                    MAX_LENGTH = "20";
                }
                if("".equals(CHECK_CONTAIN_DIGIT)) {
                    CHECK_CONTAIN_DIGIT = "enable";
                }
                if("".equals(CHECK_DISTINGGUISH_CASE)) {
                    CHECK_DISTINGGUISH_CASE = "disable";
                }
                if("".equals(CHECK_LOWER_CASE)) {
                    CHECK_LOWER_CASE = "enable";
                }
                if("".equals(CHECK_UPPER_CASE)) {
                    CHECK_UPPER_CASE = "enable";
                }
                if("".equals(CHECK_CONTAIN_SPECIAL_CHAR)) {
                    if("2".equals(SYSTEM_GRADE)) {
                        CHECK_CONTAIN_SPECIAL_CHAR = "disable";
                    }else{
                        CHECK_CONTAIN_SPECIAL_CHAR = "enable";
                        if("".equals(SPECIAL_CHAR)) {
                            SPECIAL_CHAR = DEFAULT_SPECIAL_CHAR;
                        }
                    }
                }
 
                if("".equals(CHECK_HORIZONTAL_KEY_SEQUENTIAL)) {
                    CHECK_HORIZONTAL_KEY_SEQUENTIAL = "enable";
                    if("2".equals(SYSTEM_GRADE)) {
                        LIMIT_HORIZONTAL_NUM_KEY = "4";
                    }else{
                        LIMIT_HORIZONTAL_NUM_KEY = "3";
                    }
                }
 
                if("".equals(CHECK_SLOPE_KEY_SEQUENTIAL)) {
                    CHECK_SLOPE_KEY_SEQUENTIAL = "enable";
                    if("2".equals(SYSTEM_GRADE)) {
                        LIMIT_SLOPE_NUM_KEY = "4";
                    }else{
                        LIMIT_SLOPE_NUM_KEY = "3";
                    }
                }
 
                if("".equals(CHECK_LOGIC_SEQUENTIAL)) {
                    CHECK_LOGIC_SEQUENTIAL = "enable";
                    if("2".equals(SYSTEM_GRADE)) {
                        LIMIT_LOGIC_NUM_CHAR = "4";
                    }else{
                        LIMIT_LOGIC_NUM_CHAR = "3";
                    }
 
                }
                if("".equals(CHECK_SEQUENTIAL_CHAR_SAME)) {
                    CHECK_SEQUENTIAL_CHAR_SAME = "enable";
                    if("2".equals(SYSTEM_GRADE)) {
                        LIMIT_NUM_SAME_CHAR = "4";
                    }else{
                        LIMIT_NUM_SAME_CHAR = "3";
                    }
                }
            }else{
                SYSTEM_GRADE = "3";
                CHECK_PASSWORD_LENGTH = "enable";
                MIN_LENGTH = "8";
                MAX_LENGTH = "20";
                CHECK_CONTAIN_DIGIT = "enable";
                CHECK_LOWER_CASE = "enable";
                CHECK_UPPER_CASE = "enable";
                CHECK_CONTAIN_SPECIAL_CHAR = "enable";
                CHECK_HORIZONTAL_KEY_SEQUENTIAL = "enable";
                LIMIT_HORIZONTAL_NUM_KEY = "3";
                CHECK_SLOPE_KEY_SEQUENTIAL = "enable";
                LIMIT_SLOPE_NUM_KEY = "3";
                CHECK_LOGIC_SEQUENTIAL = "enable";
                LIMIT_LOGIC_NUM_CHAR = "3";
                CHECK_SEQUENTIAL_CHAR_SAME = "enable";
                LIMIT_NUM_SAME_CHAR = "3";
            }
        }
        catch(Exception e){
            System.out.println(e);
        }
    }
}
?
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
import com.security.weakpassword.CheckPWD;
/**
 * Created by xianbin
 */
public class TestDemo {
    public static void main(String[] args) {
        System.out.println("this is a test code");
 
        boolean flag = false;
        String[] testPass = {
                null,
                "",
                "123456",
                "12345678",
                "abcdefgh",
                "123abc456",
                "1231adf@",
                "12341adf@",
                "fdahuier243335ddfa#$*&",
                "aBcd1859d4!@",
                "zaq13edfgt#",
                "Bgt5sj4#"
        };
        for (int i = 0; i < testPass.length; i++) {
            System.out.printf("testpass[%d] = %s\n", i,testPass[i]);
            flag = CheckPWD.EvalPWD(testPass[i]);
            if (flag) {
                System.out.println("secret pass.\n");
            } else {
                System.out.println("secret failed.\n");
            }
        }
    }
}

5. 配置文件

?
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
#保护系统级别 系统级别分为二级系统和三级系统
#当systemGrade不为2或者3时,系统默认使用系统级别2的规则
#当systemGrade设置为2或者3时,其他选项若未配置,则按照默认值处理,具体默认值信息见每一项说明
systemGrade=2
 
#检测密码口令长度
#当checkPasswordLength为disable时,下面两项设置无效
#其他检测功能设置为disable时,对应设置项设置数据无效
#当系统级别为23时,checkPasswordLength默认为enable
#当系统级别为23时,limitPassMinLength默认为8,limitPassMaxLength默认为20
#是否检测密码口令长度,如为enable则检测,如为disable则不检测,如为空,
checkPasswordLength=enable
#允许密码口令最小长度
limitPassMinLength=8
#允许密码口令最大长度,如为空,则不设置上限
limitPassMaxLength=20
 
#是否包含数字、小写字母、大写字母、特殊符号
#当设置checkContainUpperLowerCase为enable时,区分大小写
#当系统级别为2时:checkContainDigit默认为enable,checkContainUpperLowerCase默认为disable
#当系统级别为2时,checkContainLowerCase默认为disable,checkContainUpperCase默认为disable
#当系统级别为2时,checkContainSpecialChar默认为disable
#当系统级别为3时:checkContainDigit默认为enable,checkContainUpperLowerCase默认为disable
#当系统级别为3时,checkContainLowerCase默认为disable,checkContainUpperCase默认为disable
#当系统级别为3时,checkContainSpecialChar默认为enable
#是否检测包含数字
checkContainDigit=enable
#是否检测包含大小写字母,区分密码口令大小写
checkContainUpperLowerCase = disable
#是否检测包含小写字母
checkContainLowerCase = enable
#是否检测包含大写字母
checkContainUpperCase = enable
#是否检测包含特殊符号
checkContainSpecialChar=disable
#支持自定义特殊符号集合
specialCharSet="!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"
 
#检测键盘按键连续 比如qwer、1qaz、0okm等
#允许横向最大连续num为7,最小为3
#允许斜向最大连续num为4,最小为3
#当系统级别为2时:checkHorizontalKeySequential默认为enable,horizontalKeyLimitNum默认为4
#当系统级别为2时,checkSlopeKeySequential默认为enable,slopeKeyLimitNum默认为4
#当系统级别为3时:checkHorizontalKeySequential默认为enable,horizontalKeyLimitNum默认为3
#当系统级别为3时,checkSlopeKeySequential默认为enable,slopeKeyLimitNum默认为3
#是否检测键盘横向连续
checkHorizontalKeySequential=enable
#允许键盘横向连续最小数值,如为空,则设置为默认值
horizontalKeyLimitNum=4
#是否检测键盘斜向连续
checkSlopeKeySequential=enable
#允许键盘斜向连续最小数值,如为空,则设置为默认值
slopeKeyLimitNum=4
 
#检测逻辑位置连续 比如1234、abcd等
#当系统级别为2时,checkLogicSequential默认为enable,logicLimitNum默认为4
#当系统级别为3时,checkLogicSequential默认为enable,logicLimitNum默认为3
#是否检测逻辑位置连续
checkLogicSequential=enable
#允许逻辑位置连续最小数值,如为空,则设置为默认值
logicLimitNum=4
 
#检测相邻字符相同 比如aaaa、2222、@@@@等
#当系统级别为2时,checkSequentialCharSame默认为enable,sequentialCharNum默认为4
#当系统级别为3时,checkSequentialCharSame默认为enable,sequentialCharNum默认为3
#是否检测相邻字符相同
checkSequentialCharSame=enable
#允许相邻位置相同最小连续数,如为空,则设置为默认值
sequentialCharNum=4

以上为个人经验,希望能给大家一个参考,也希望大家多多支持服务器之家。

原文链接:https://water.blog.csdn.net/article/details/83114315