首页 > 其他 > 详细

求密码强度

时间:2020-07-02 09:58:43      阅读:57      评论:0      收藏:0      [点我收藏+]

密码按如下规则进行计分,并根据不同的得分为密码进行安全等级划分。

一、密码长度:

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:  非常弱

 

private static int gradeLen(String pwd) {
int grade = 5;
int length = pwd.length();
if(length <= 4){
grade = 5;
}else if(4 < length && length < 8){
grade = 10;
}else if(7 < length ){
grade = 25;
}
return grade;
}

private static int gradeAlpaha(String pwd) {
int alpaha = 0 ;
int small = 0 ;
int big = 0 ;
for (char c : pwd.toCharArray()) {
boolean isSmall = (‘a‘ <= c && c <= ‘z‘);
boolean isBig = (‘A‘ <= c && c <= ‘Z‘);
if(isSmall){
small++;
}
if(isBig){
big++;
}
if(isSmall || isBig){
alpaha++;
}
}
int length = pwd.length();
if(alpaha == 0){
return 0;
}
if(length == small || length == big){
return 10;
}
return 20;
}
private static int gradeDiglate(String pwd) {
int numCount = 0;
for (char c : pwd.toCharArray()) {
if(c >= ‘0‘ && c<= ‘9‘){
numCount++;
if(numCount > 1){
break;
}
}
}
if(numCount == 0){
return 0;
}else if (numCount == 1){
return 10;
}
return 20;
}

private static int gradeSymbol(String pwd) {
int symbolCount = 0;
for (char c : pwd.toCharArray()) {
if("!\"#$%&‘()*+,-./".contains(c+"")){
symbolCount++;
if(symbolCount > 1){
break;
}
}
}
if(symbolCount == 0){
return 0;
}else if (symbolCount == 1){
return 10;
}
return 20;
}
private static int gradeRewd(String pwd) {
int symbolCount = 0;
for (char c : pwd.toCharArray()) {
if("!\"#$%&‘()*+,-./".contains(c+"")){
symbolCount++;
if(symbolCount > 1){
break;
}
}
}
if(symbolCount == 0){
return 0;
}else if (symbolCount == 1){
return 10;
}
return 20;
}

 

求密码强度

原文:https://www.cnblogs.com/dongma/p/13222778.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!