问题描述:密码按如下规则进行计分,并根据不同的得分为密码进行安全等级划分。
一、密码长度:
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
请根据输入的密码字符串,进行安全评定。
注:
字母:a-z, A-Z
数字:0-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;
}
知识点: 枚举
题目来源: 内部整理
练习阶段: 初级
运行时间限制: 10Sec
内存限制: 128MByte
输入:
输入一个string的密码
输出:
输出密码等级
样例输入: 38$@NoNoNo
一、密码长度:
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
请根据输入的密码字符串,进行安全评定。
注:
字母:a-z, A-Z
数字:0-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;
}
知识点: 枚举
题目来源: 内部整理
练习阶段: 初级
运行时间限制: 10Sec
内存限制: 128MByte
输入:
输入一个string的密码
输出:
输出密码等级
样例输入: 38$@NoNoNo
样例输出: VERY_SECURE
代码:
#include <iostream>
#include <string>
using namespace std;
string getpass(string pwd);
int main()
{
string pwd;
getline(cin,pwd);
cout<<getpass(pwd)<<endl;
return 0;
}
string getpass(string pwd)
{
int score=0;
int size=pwd.size();
bool haveupper=false;
bool havelower=false;
bool haveletter=false;
int numcount=0;
int charcount=0;
int i=0;
for(i=0;i<size;i++)
{
if(pwd[i]>='A'&&pwd[i]<='Z')
{
haveupper=true;
}
else if(pwd[i]>='a'&&pwd[i]<='z')
{
havelower=true;
}
else if(pwd[i]>='0'&&pwd[i]<='9')
{
numcount++;
}
else if(pwd[i]!= ' ')
{
charcount++;
}
}
if(size<=4)
{
score=score+5;
}
else if(size>=5&&size<=7)
{
score=score+10;
}
else if(size>=8)
{
score=score+25;
}
if((haveupper&&!havelower)||(havelower&&!haveupper))
{
haveletter=true;
score=score+10;
}
else if(havelower&&haveupper)
{
haveletter=true;
score=score+20;
}
if(numcount==1)
{
score=score+10;
}
else if(numcount>1)
{
score=score+20;
}
if(charcount==1)
{
score=score+10;
}
else if(charcount>1)
{
score=score+25;
}
if(numcount>=1&&haveletter&&charcount==0)
{
score=score+2;
}
else if(numcount>=1&&haveletter&&charcount>=1)
{
score=score+3;
}
else if(numcount>=1&&havelower&&haveupper&&charcount>=1)
{
score=score+5;
}
if (score >= 90)
return "VERY_SECURE";
else if(score >= 80)
return "SECURE";
else if(score >= 70)
return "VERY_STRONG";
else if(score >=60)
return "STRONG";
else if(score >= 50)
return "AVERAGE";
else if(score >= 25)
return "WEAK";
else
return "VERY_WEAK";
}