华为OJ——密码强度等级

密码强度等级

题目描述

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

       一、密码长度:

       5 小于等于个字符

       10 : 5 字符

       25 大于等于个字符

       二、字母:

       0 没有字母

       10 全都是小(大)写字母

       20 大小写混合字母

       三、数字:

       0 没有数字

       10 : 1 个数字

       20 大于个数字

       四、符号:

       0 没有符号

       10 : 1 个符号

       25 大于个符号

       五、奖励:

       2 字母和数字

       3 字母、数字和符号

       5 大小写字母、数字和符号

       最后的评分标准:

       >= 90: 非常安全

       >= 80: 安全(Secure

       >= 70: 非常强

       >= 60: 强(Strong

       >= 50: 一般(Average

       >= 25: 弱(Weak

       >= 0:  非常弱

对应输出为:

  VERY_WEAK,

   WEAK,    

   AVERAGE,    

   STRONG,     

   VERY_STRONG,

   SECURE,     

   VERY_SECURE 

       请根据输入的密码字符串,进行安全评定。

       注:

       字母:a-z, A-Z

       数字:-9

       符号包含如下: (ASCII码表可以在UltraEdit的菜单view->ASCII Table查看)

       !"#$%&'()*+,-./     (ASCII码:x21~0x2F)

       :;<=>?@             (ASCII<=><=><=><=><=>码:x3A~0x40)

       [\]^_`              (ASCII码:x5B~0x60)

  {|}~                (ASCII码:x7B~0x7E)

接口描述:

 Input Param 
      String pPasswordStr:    密码,以字符串方式存放。

 Return Value
   根据规则评定的安全等级。

 
 public static Safelevel GetPwdSecurityLevel(String pPasswordStr)
 {
     /*在这里实现功能*/
  return null;
 }

输入描述:

输入一个string的密码

输出描述:

输出密码等级

输入例子:

38$@NoNoNo

输出例子:

VERY_SECURE

解答代码:

#include<iostream>
#include<fstream>
#include<string>
#include<cstring>
#include<algorithm>
#include<sstream>
using namespace std;

int main()
{
    //freopen("1.txt","r",stdin);
    string password;
    int i,score;
    while(cin>>password)
    {
        score=0;
        int length=password.length();
        if(length>=8)
            score+=25;
        else if(length>=5)
            score+=10;
        else
            score+=5;
        //字母 数字
        int flagA=0,flagBig=0,flagSmall=0;
        int count=0,flagNum=0;
        int cou=0,flagOther=0;
        for(i=0; i<length; i++)
        {
            if(password[i]>='a' && password[i]<='z')
            {
                flagSmall=1;
                flagA=1;
            }
            else if(password[i]>='A' && password[i]<='Z')
            {
                flagBig=1;
                flagA=1;
            }
            else if(password[i]>='0' && password[i]<='9')
            {
                flagNum=1;
                count++;
            }
            else
            {
                flagOther=1;
                cou++;
            }
        }
        if(flagBig && flagSmall)
            score+=20;
        else if(flagBig || flagSmall)
            score+=10;
        else
            score+=0;

        if(flagNum && count>1)
            score+=20;
        else if(flagNum && count==1)
            score+=10;
        else
            score+=0;

        if(flagOther && cou>1)
            score+=25;
        else if(flagOther && cou==1)
            score+=10;
        else
            score+=0;

        if(flagOther && flagNum && flagBig && flagSmall)
            score+=5;
        else if(flagOther && flagNum && flagA)
            score+=3;
        else if(flagNum && flagA)
            score+=2;

        //cout<<score<<endl;
        if(score>=90)
            cout<<"VERY_SECURE"<<endl;
        else if(score>=80)
            cout<<"SECURE"<<endl;
        else if(score>=70)
            cout<<"VERY_STRONG"<<endl;
        else if(score>=60)
            cout<<"STRONG"<<endl;
        else if(score>=50)
            cout<<"AVERAGE"<<endl;
        else if(score>=25)
            cout<<"WEAK"<<endl;
        else if(score>=0)
            cout<<"VERY_WEAK"<<endl;
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值