题解 | #密码强度等级#

密码强度等级

http://www.nowcoder.com/practice/52d382c2a7164767bca2064c1c9d5361

import java.util.Scanner;
import java.util.regex.Pattern;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        Main sol = new Main();
        String rs = sol.pwdStrength(s);
        System.out.println(rs);
    }

    public String pwdStrength (String s) {
        // 分数
        int fraction = 0;
        // 密码长度
        int s_length = s.length();
        // 含有字母的个数
        int letter_count = s.replaceAll("[^a-zA-Z]", "").length();
        // 含有的数字个数
        int number_count = s.replaceAll("[^0-9]", "").length();
        // 含有的符号个数
        int char_count = s.replaceAll("[0-9a-zA-Z]", "").length();

        // 密码长度得分
        if (s_length <= 4) {
            fraction += 5;
        }
        else if (s_length <= 7) {
            fraction += 10;
        }
        else if (s_length >= 8) {
            fraction += 25;
        }


        // 是否含大小写字母
        boolean upper_letter = Pattern.matches(".*[A-Z]+.*", s);
        boolean lower_letter = s.matches(".*[a-z]+.*");
        // 仅大/小写字母的个数
        int upper_letter_count = s.replaceAll("[^A-Z]", "").length();
        int lower_letter_count = s.replaceAll("[^a-z]", "").length();
        // 含字母-得分
        if (lower_letter && upper_letter) {
            fraction += 20;
        }
        else if (upper_letter_count > 0) {
            fraction += 10;
        }
        else if (lower_letter_count > 0) {
            fraction += 10;
        }
        else if (letter_count == 0) {
            fraction += 0;
        }

        // 数字-得分
        if (number_count == 0) {
            fraction += 0;
        }
        else if (number_count == 1) {
            fraction += 10;
        }
        else if (number_count > 1) {
            fraction += 20;
        }

        // 符号-得分
        if (char_count == 0) {
            fraction += 0;
        }
        else if (char_count == 1) {
            fraction += 10;
        }
        else if (char_count > 1) {
            fraction += 25;
        }

        // 奖励-得分
        if (upper_letter &&
                lower_letter &&
                number_count > 0 &&
                char_count > 0) {
            fraction += 5;
        }
        else if (letter_count > 0 &&
                number_count > 0 &&
                char_count > 0) {
            fraction += 3;
        }
        else if (letter_count > 0 &&
                number_count > 0) {
            fraction += 2;
        }

        if (fraction >= 90) {
            return "VERY_SECURE";
        }
        else if (fraction >= 80) {
            return "SECURE";
        }
        else if (fraction >= 70) {
            return "VERY_STRONG";
        }
        else if (fraction >= 60) {
            return "STRONG";
        }
        else if (fraction >= 50) {
            return "AVERAGE";
        }
        else if (fraction >= 25) {
            return "WEAK";
        }
        else if (fraction >= 0) {
            return "VERY_WEAK";
        }
        return null;
    }
}

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-09 12:11
点赞 评论 收藏
分享
Twilight_m...:表格简历有点难绷。说说个人看法: 1.个人基本情况里好多无意义信息,什么婚姻状况、健康状况、兴趣爱好、户口所在地、身份证号码、邮政编码,不知道的以为你填什么申请表呢。 2.校内实践个人认为对找工作几乎没帮助,建议换成和测开有关的项目,实在没得写留着也行。 3.工作经历完全看不出来是干什么的,起码看着和计算机没啥关系,建议加强描述,写点你在工作期间的实际产出、解决了什么问题。 4.个人简述大而空,看着像AI生成,感觉问题最大。“Python,C,C++成为我打造高效稳定服务的得力工具”、“我渴望凭借自身技术知识与创新能力,推动人工智能技术的应用发展,助力社会实现智能化转型”有种小学作文的美感。而且你确定你个人简述里写的你都会嘛?你AI这块写的什么“深入研究”,发几篇顶会的硕博生都不一定敢这么写。而且你AI这块的能力和软测也完全无关啊。个人简述建议写你对哪些技术栈、哪些语言、哪些生产工具的掌握,写的有条理些,而且最好是和测开强相关的。
点赞 评论 收藏
分享
05-12 17:00
门头沟学院 Java
king122:你的项目描述至少要分点呀,要实习的话,你的描述可以使用什么技术,实现了什么难点,达成了哪些数字指标,这个数字指标尽量是真实的,这样面试应该会多很多,就这样自己包装一下,包装不好可以找我,我有几个大厂最近做过的实习项目也可以包装一下
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
昨天 13:54
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务