zoukankan      html  css  js  c++  java
  • 求密码强度

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

    一、密码长度:

    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;
    }
  • 相关阅读:
    碰撞的蚂蚁 牛客网 程序员面试金典 C++ Java Python
    空格替换 牛客网 程序员面试金典 C++ Python
    穿点最多的直线 牛客网 程序员面试金典 C++
    第K个数 牛客网 程序员面试金典 C++ Python
    React Native之图片/宽高/字体平台适配
    echarts玩转图表之矩形树图
    如何评价 Vue 的 Function-based Component?
    如何写一个像axios那样牛叉的请求库
    精读《Nuxtjs》
    react hooks系列之useRef
  • 原文地址:https://www.cnblogs.com/dongma/p/13222778.html
Copyright © 2011-2022 走看看