题目描述
密码按如下规则进行计分,并根据不同的得分为密码进行安全等级划分。
一、密码长度:
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
密码按如下规则进行计分,并根据不同的得分为密码进行安全等级划分。
一、密码长度:
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
输入描述:
输入一个string的密码
输出描述:
输出密码等级
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (scanner.hasNext())
{
String str = scanner.next();
int total = 0;
int len = str.length();
int upperCh = 0;
int lowCh = 0;
int digit = 0;
int symbol = 0;
int bonus = 0;
if (len <= 4)
total += 5;
else if (len <= 7)
total += 10;
else
total += 25;
for (char c: str.toCharArray())
{
if (c >= 'a' && c <= 'z')
lowCh++;
else if (c >= 'A' && c <= 'Z')
upperCh++;
else if (c >= '0' && c <= '9')
digit++;
else
symbol++;
}
if ((lowCh == 0 && upperCh != 0) || (lowCh != 0 && upperCh == 0))
total += 10;
else if (lowCh != 0 && upperCh != 0)
total += 20;
if (digit == 1)
total += 10;
else if (digit > 1)
total += 20;
if (symbol == 1)
total += 10;
else if (symbol > 1)
total += 25;
if ((upperCh + lowCh != 0) && digit != 0 && symbol == 0)
bonus = 2;
else if ((upperCh + lowCh != 0) && digit != 0 && symbol != 0)
{
bonus = 3;
if (upperCh != 0 && lowCh != 0)
bonus = 5;
}
total += bonus;
if (total >= 90)
System.out.println("VERY_SECURE");
else if (total >= 80)
System.out.println("SECURE");
else if (total >= 70)
System.out.println("VERY_STRONG");
else if (total >= 60)
System.out.println("STRONG");
else if (total >= 50)
System.out.println("AVERAGE");
else if (total >= 25)
System.out.println("WEAK");
else if (total >= 0)
System.out.println("VERY_WEAK");
}
}
}