package com.wx.pwd;
/**
* 检测密码强度
*
* @author venshine
*/
public class CheckStrength {
public enum LEVEL {
EASY, MIDIUM, STRONG, VERY_STRONG, EXTREMELY_STRONG
}
/**
* NUM 数字
* SMALL_LETTER 小写字母
* CAPITAL_LETTER 大写字母
* OTHER_CHAR 特殊字符
*/
private static final int NUM = 1;
private static final int SMALL_LETTER = 2;
private static final int CAPITAL_LETTER = 3;
private static final int OTHER_CHAR = 4;
/**
* 简单的密码字典
*/
private final static String[] DICTIONARY = {
"password", "abc123", "iloveyou", "adobe123", "123123", "sunshine",
"1314520", "a1b2c3", "123qwe", "aaa111", "qweasd", "admin", "passwd"};
/**
*检查字符类型,包括num、大写字母、小写字母和其他字符。
*
* @param c
* @return
*/
private static int checkCharacterType(char c) {
if (c >= 48 && c <= 57) {
return NUM;
}
if (c >= 65 && c <= 90) {
return CAPITAL_LETTER;
}
if (c >= 97 && c <= 122) {
return SMALL_LETTER;
}
return OTHER_CHAR;
}
/**
* 按不同类型计算密码的数量
*
* @param passwd
* @param type
* @return
*/
private static int countLetter(String passwd, int type) {
int count = 0;
if (null != passwd && passwd.length() > 0) {
for (char c : passwd.toCharArray()) {
if (checkCharacterType(c) == type) {
count++;
}
}
}
return count;
}
/**
* 检查密码的强度
*
* @param passwd
* @return strength level
*/
public static int checkPasswordStrength(String passwd) {
if (StringUtils.equalsNull(passwd)) {
throw new IllegalArgume
java密码强度检测
最新推荐文章于 2024-08-07 16:07:44 发布
本文介绍如何使用Java进行密码强度检测,包括正则表达式验证、复杂度分析等方法,确保密码的安全性。
摘要由CSDN通过智能技术生成