密码强度等级

题目描述
密码按如下规则进行计分,并根据不同的得分为密码进行安全等级划分。
一、密码长度:
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");
        }
    }
}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值