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;
    }
  • 相关阅读:
    手机浏览器
    一招封住360流氓
    原来在Delphi中的类型是严格匹配的
    Windows 7下面3389远程连接时“超出最大连接数”解决办法
    大家开发过淘宝商城API应用的么?
    adodb.recordset 添加记录后无法取得ID
    VBATrack Picture
    java web后台开发SSM框架(Spring+SpringMVC+MyBaitis)搭建与优化
    VBATrack MsgBox
    VBATrack 暂停3秒运行
  • 原文地址:https://www.cnblogs.com/dongma/p/13222778.html
Copyright © 2011-2022 走看看