密码按如下规则进行计分,并根据不同的得分为密码进行安全等级划分。
一、密码长度:
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
一、密码长度:
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int GetPwdSecurityLevel(char *password)
{
int score[5],sum=0;
int len,i;
int alphaflag=0;
int digitCnt=0;
int punctCnt=0;
char *p=password;
len=strlen(password);
if(len>7)
score[0]=25;
else if(len>4)
score[0]=10;
else
score[0]=0;
while(*p!='\0')
{
if(isalpha(*p))
{
if(alphaflag==0)
{
if(isupper(*p))
alphaflag=1;
else
alphaflag=2;
}
else if(alphaflag==1)
{
if(islower(*p))
alphaflag=3;
}
else if(alphaflag==2)
{
if(isupper(*p))
alphaflag=3;
}
}
else if(isdigit(*p))
{
digitCnt++;
}
else if(ispunct(*p))
{
punctCnt++;
}
p++;
}
if(alphaflag>2)
score[1]=20;
else if(alphaflag>0)
score[1]=10;
else
score[1]=0;
if(digitCnt>1)
score[2]=20;
else if(digitCnt>0)
score[2]=10;
else
score[2]=0;
if(punctCnt>1)
score[3]=25;
else if(punctCnt>0)
score[3]=10;
else
score[3]=0;
if(score[1]>0&&score[2]>0)
{
if(score[3]>0)
{
if(score[1]>10)
score[4]=5;
else
score[4]=3;
}
else
score[4]=2;
}
else
score[4]=0;
for(i=0;i<5;i++)
{
sum+=score[i];
printf("%d,",score[i]);
}
printf("\n%d\n",sum);
return sum;
}
int main()
{
char password[2048],result[20];
int sum=0;
scanf("%[^\n]",password);
sum=GetPwdSecurityLevel(password);
if(sum>=90)
strcpy(result,"VERY_SECURE");
else if(sum>=80)
strcpy(result,"SECURE");
else if(sum>=70)
strcpy(result,"VERY_STRONG");
else if(sum>=60)
strcpy(result,"STRONG");
else if(sum>=50)
strcpy(result,"AVERAGE");
else if(sum>=25)
strcpy(result,"WEAK");
else
strcpy(result,"VERY_WEAK");
printf("%s\n",result);
return 0;
}