检测密码强度工具类
发布日期:2021-06-29 15:24:31
浏览次数:3
分类:技术文章
本文共 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 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
不错!
[***.144.177.141]2024年04月08日 22时07分16秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
485通信自动收发电路,历史上最详细的解释
2019-04-29
一位头发发白的神人教你怎么写程序,运维,买电脑,写文章,平面设计!
2019-04-29
「第三篇」全国电子设计竞赛,这些你必须知道的比赛细节,文末附上近十年电赛题目下载...
2019-04-29
5G小科普(漫画版,So easy!)
2019-04-29
「第四篇」电赛控制题可以准备一些什么?
2019-04-29
「第六篇」对于电赛,我们应该看重什么?
2019-04-29
树莓派翻车了
2019-04-29
这位电子工程师,你不能错过。
2019-04-29
「重磅猜题之第二篇」2019年大学生电子设计竞赛
2019-04-29
干货分享 JVM 之第 3 篇 —— Java 内存结构相关
2019-04-29
基于 Hystrix 高并发服务限流第 2 篇 —— 服务隔离(线程池隔离、信号量隔离)
2019-04-29
SpringBoot 整合 JWT 实现统一认证
2019-04-29
TypeError: this.getOptions is not a function
2019-04-29
el-table 二维数组合并行
2019-04-29
UR5e机械臂运行一直阻塞在waitForServer
2019-04-29
ROS把pkg1下的某个头文件和源文件生成动态链接库供pkg2调用
2019-04-29
使用urdf_tutorial快速可视化urdf文件
2019-04-29
SQl 数据完整性(随堂博客)
2019-04-29
左连接、右连接、内连接
2019-04-29