华为OJ 初级:密码强度等级
2016-07-28 23:24
323 查看
描述 | 密码按如下规则进行计分,并根据不同的得分为密码进行安全等级划分。 一、密码长度: 5 分: 小于等于4 个字符 10 分: 5 到7 字符 25 分: 大于等于8 个字符 二、字母: 0 分: 没有字母 10 分: 全都是小(大)写字母 20 分: 大小写混合字母 三、数字: 0 分: 没有数字 10 分: 1 个数字 20 分: 大于1 个数字 四、符号: 0 分: 没有符号 10 分: 1 个符号 25 分: 大于1 个符号 五、奖励: 2 分: 字母和数字 3 分: 字母、数字和符号 5 分: 大小写字母、数字和符号 最后的评分标准: >= 90: 非常安全 >= 80: 安全(Secure) >= 70: 非常强 >= 60: 强(Strong) >= 50: 一般(Average) >= 25: 弱(Weak) >= 0: 非常弱 对应输出为: VERY_WEAK, WEAK, AVERAGE, STRONG, VERY_STRONG, SECURE, VERY_SECURE 请根据输入的密码字符串,进行安全评定。 注: 字母:a-z, A-Z 数字:-9 符号包含如下: (ASCII码表可以在UltraEdit的菜单view->ASCII Table查看) !"#$%&'()*+,-./ (ASCII码:x21~0x2F) :;<=>?@ (ASCII<=><=><=><=><=>码:x3A~0x40) [\]^_` (ASCII码:x5B~0x60) {|}~ (ASCII码:x7B~0x7E)接口描述: Input Param String pPasswordStr: 密码,以字符串方式存放。 Return Value 根据规则评定的安全等级。 public static Safelevel GetPwdSecurityLevel(String pPasswordStr) { /*在这里实现功能*/ return null; } |
---|---|
知识点 | 枚举 |
运行时间限制 | 10M |
内存限制 | 128 |
输入 | 输入一个string的密码 |
输出 | 输出密码等级 |
样例输入 | 38$@NoNoNo |
样例输出 | VERY_SECURE |
/*分为五个部分,分别计算每部分的得分,最后加起来 * 使用正则表达式判断 * */ import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); String input = sc.next().trim(); sc.close(); int lengthScore = lengthScore(input); int charScore = charScore(input); int numScore = numScore(input); int fuhaoScore = fuhaoScore(input); int awardScore = awardScore(input); int sum = lengthScore + charScore+numScore+fuhaoScore+awardScore; String output = null; if(sum >= 0) output = "VERY_WEAK"; if(sum >= 25) output = "WEAK"; if(sum >= 50) output = "AVERAGE"; if(sum >= 60) output = "STRONG"; if(sum >= 70) output = "VERY_STRONG"; if(sum >= 80) output = "SECURE"; if(sum >= 90) output = "VERY_SECURE "; System.out.println(output); } private static int lengthScore(String input) { int score = 0; if (input.length() >= 8) score = 25; else if (input.length() <= 4) score = 5; else score = 10; return score; } private static int charScore(String input) { int score = 0; Pattern pattern = Pattern.compile("[a-zA-Z]"); Matcher matcher; int flag = 0; String[] string = input.trim().split(""); for (int i = 0; i < string.length; i++) { matcher = pattern.matcher(string[i]); if (matcher.matches()) flag++; } if (flag != 0) { if (input.toLowerCase().equals(input)) score = 10; else score = 20; } else score = 0; return score; } private static int numScore(String input) { int score = 0; Pattern pattern = Pattern.compile("[0-9]"); Matcher matcher; int flag = 0; String[] string = input.trim().split(""); for (int i = 0; i < string.length; i++) { matcher = pattern.matcher(string[i]); if (matcher.matches()) flag++; } if (flag != 0) { if (flag > 1) score = 20; else score = 10; } else score = 0; return score; } private static int fuhaoScore(String input) { int score = 0; Pattern pattern = Pattern .compile(".*[`~!@#$^&*()=|{}':;',\\[\\].<>/?~!@#&*()&;—|{}‘;:”“'。,、?].*"); Matcher matcher; int flag = 0; String[] string = input.trim().split(""); for (int i = 0; i < string.length; i++) { matcher = pattern.matcher(string[i]); if (matcher.matches()) flag++; } if (flag != 0) { if (flag > 1) score = 25; else score = 10; } else score = 0; return score; } private static int awardScore(String input) { int score = 0; if(numScore(input) > 0 && charScore(input) > 0){ score = 2; if(fuhaoScore(input) > 0){ score = 3; if(charScore(input) == 20) score = 5; } } return score; } }
相关文章推荐
- Centos7 安装vnc
- 28.字符串替换
- url带斜杠和不带斜杠对seo优化的影响
- [树状数组] poj 3416 Crossing
- windbg 脚本简单入门
- WPF MVVM 架构 Step By Step(5)(添加actions和INotifyPropertyChanged接口)
- sort qsort 用法总结
- 27.分数加减法
- Face Detection with the Faster R-CNN
- Python网络请求模块requests
- 26.两点距离
- 设计模式---行为类型---策略
- POJ 3172 Scales (剪枝深搜)
- 从胶片到 CCD
- 用SQL语句创建表
- 解决AFN的post请求错误:Error Domain=NSCocoaErrorDomain Code=3840
- 打造专属的Chromium for Android
- 控制成本,控制成本知识点,挣值和实际成本、EAC,ETC.TCPI解析表
- 文章标题HDU 4355:codeforces 621C:Wet Shark and Flowers(水)
- POJ 3503 神特么的 BFS