检测密码强度工具类
发布日期:2021-06-29 15:24:31
浏览次数:2
分类:技术文章
本文共 4481 字,大约阅读时间需要 14 分钟。
package com.lxm.tools;import java.util.regex.Matcher;import java.util.regex.Pattern;public class CheckPWD { public static Safelevel checkPasswordStrength(String c) { Safelevel d = Safelevel.WEAK; if (isEmptyPassword(c)) { return d; } if (isTooShort(c)) { d = Safelevel.WEAK; } else { if (hasNum(c) && hasLetter(c) && hasSymbol(c)) { d = Safelevel.SECURE; } else { if (hasNum(c) && hasLetter(c)) { d = Safelevel.STRONG; } else { if (hasNum(c) && hasSymbol(c)) { d = Safelevel.STRONG; } else { if (hasSymbol(c) && hasLetter(c)) { d = Safelevel.STRONG; } else { if (isAllNum(c) || isAllLetter(c) || isAllSymbol(c)) { d = Safelevel.WEAK; } } } } } } return d; } public enum Safelevel { WEAK, /* 弱 */ STRONG, /* 强 */ SECURE, /* 安全 */ } public static boolean hasNum(String content) { boolean flag = false; Pattern p = Pattern.compile(".*\\d+.*"); Matcher m = p.matcher(content); if (m.matches()) flag = true; return flag; } public static boolean hasSymbol(String content) { boolean flag = false; Pattern p = Pattern.compile(".*[a-zA-Z0-9\\s<>;'\\\\]+.*"); Matcher m = p.matcher(content); if (m.matches()) flag = true; return flag; } public static boolean isAllSymbol(String content) { boolean flag = false; Pattern p = Pattern.compile("^[a-zA-Z0-9\\s<>;'\\\\]+$"); Matcher m = p.matcher(content); if (m.matches()) flag = true; return flag; } public static boolean hasSpace(String content) { boolean flag = false; Pattern p = Pattern.compile(".*\\s+.*"); Matcher m = p.matcher(content); if (m.matches()) flag = true; return flag; } public static boolean hasIllegalSymbol(String content) { boolean flag = false; Pattern p = Pattern.compile(".*[\\s<>;'\\\\].*"); Matcher m = p.matcher(content); if (m.matches()) flag = true; return flag; } public static boolean hasLetter(String content) { boolean flag = false; Pattern p = Pattern.compile(".*[a-zA-Z]+.*"); Matcher m = p.matcher(content); if (m.matches()) flag = true; return flag; } public static boolean isAllLetter(String content) { boolean flag = false; Pattern p = Pattern.compile("^[a-zA-Z]+$"); Matcher m = p.matcher(content); if (m.matches()) flag = true; return flag; } private static boolean isEmptyPassword(String b) { return (b == null || b.length() == 0); } private static boolean isTooShort(String b) { return b.length() < 6; } public static boolean isAllNum(String content) { boolean flag = false; Pattern p = Pattern.compile("^\\d+$"); Matcher m = p.matcher(content); if (m.matches()) flag = true; return flag; } public static boolean hasRepeat6Chars(String content) { boolean flag = false; Pattern p = Pattern.compile(".*([0-9a-zA-Z])\\1{5}.*"); Matcher m = p.matcher(content); if (m.matches()) flag = true; return flag; } public static boolean hasIncrease6Chars(String g) { if (g == null || g.length() < 6) { return false; } char h = g.charAt(0); char i = 1; char j = 1; for (j = 1; j < g.length(); j++) { char f = g.charAt(j); if (f == h + 1) { i++; if (i >= 6) { return true; } } else { i = 1; } h = f; } return false; } public static boolean hasDecrease6Chars(String g) { if (g == null || g.length() < 6) { return false; } char h = g.charAt(0); char i = 1; char j = 1; for (j = 1; j < g.length(); j++) { char f = g.charAt(j); if (f == h - 1) { i++; if (i >= 6) { return true; } } else { i = 1; } h = f; } return false; } public static boolean hasAllIncreaseChars(String g) { if (g == null) { return false; } int i = g.length(); char h = g.charAt(0); char j = 1; char k = 1; for (k = 1; k < g.length(); k++) { char l = g.charAt(k); if (l == h + 1) { j++; if (j >= i) { return true; } } else { j = 1; } h = l; } return false; } public static boolean hasAllDecreaseChars(String g) { if (g == null) { return false; } int i = g.length(); char h = g.charAt(0); char j = 1; char k = 1; for (k = 1; k < i; k++) { char l = g.charAt(k); if (l == h - 1) { j++; if (j >= i) { return true; } } else { j = 1; } h = l; } return false; } public static boolean isAllSameChars(String content) { if (content == null || content.length() < 2) { return false; } char h = content.charAt(0); char e = 1; for (e = 1; e < content.length(); e++) { char f = content.charAt(e); if (f != h) { return false; } } return true; }}
转载地址:https://codegg.blog.csdn.net/article/details/49689449 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
表示我来过!
[***.240.166.169]2024年05月01日 08时25分16秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
7行代码击败整个金融业,这对20多岁的爱尔兰兄弟是如何做到的?
2019-04-29
2020十大编程博客:私藏的宝藏编程语言博客大放送!
2019-04-29
编程中的角色选择:哪类工作角色最适合你?
2019-04-29
10种算法一文打尽!基本图表算法的视觉化阐释
2019-04-29
未来属于人工智能工程师,但成功转型不容易
2019-04-29
科技界“挠头”:困扰科技界可持续发展的难题
2019-04-29
20年后,这5种编码语言可能就消失了……
2019-04-29
标准出现问题,人工智能正在走向错误的方向
2019-04-29
如何使用Python实现最低有效位隐写术?
2019-04-29
湮没在赞誉之中,科学史上鲜为人知的五大“败笔”
2019-04-29
别再对分类变量进行独热编码!你还有更好的选择
2019-04-29
如果不能用Python执行机器学习,那该用什么呢?
2019-04-29
不论何时,互联网从业者一直幸福着~
2019-04-29
mysql用户口令中含有特殊字符@的情况下,如何正确链接数据库
2019-04-29
SpringFox接口文档API DOC
2019-04-29
netty优化策略
2019-04-29
架构师知识体系全景图
2019-04-29
guava中EventBus(事件总线)源码分析与使用
2019-04-29
程序员成神之路文章目录
2019-04-29
SASS软件的成熟度模型总结
2019-04-29