密码等级判断

#include <iostream>
#include <string>
using namespace std;

//密码等级计算
int LengthAdd(string Password)//密码长度
{
	if (Password.length() <= 4)
		return 5;
	else if (Password.length() >= 5 && Password.length() <= 7)
		return 10;
	return 25;
}

int LetterAdd(string Password)//字母
{
	int UpperLetter = 0;
	int LowerLetter = 0;
	for (int i = 0; i < Password.size(); i++){
		if (Password[i] >= 'A' && Password[i] <= 'Z')
			UpperLetter++;
		else if (Password[i] >= 'a' && Password[i] <= 'z')
			LowerLetter++;
	}

	if (UpperLetter != 0 && LowerLetter != 0)
		return 20;
	else if ((UpperLetter == 0 && LowerLetter != 0) || (UpperLetter != 0 && LowerLetter == 0))
		return 10;
	return 0;
}

int IntegerAdd(string Password)//数字
{
	int NumOfInteger = 0;
	for (int i = 0; i<Password.size(); i++){
		if (Password[i] >= '0' && Password[i] <= '9')
			NumOfInteger++;
	}

	if (NumOfInteger == 0)
		return 0;
	else if (NumOfInteger == 1)
		return 10;
	return 20;
}

int SymbolAdd(string Password)//符号
{
	int NumOfSymbol = 0;
	for (int i = 0; i<Password.size(); i++){
		char ch = Password[i];
		if ((ch >= 0x21 && ch <= 0x2F) || (ch >= 0x3A && ch <= 0x40) || (ch >= 0x5B && ch <= 0x60) || (ch >= 0x7B && ch <= 0x7E))
			NumOfSymbol++;
	}
	if (NumOfSymbol == 0)
		return 0;
	else if (NumOfSymbol == 1)
		return 10;
	return 25;
}

int AwardAdd(string Password)//字母,符号,数字判断
{
	int LetterNum = LetterAdd(Password);
	int IntegerNum = IntegerAdd(Password);
	int SymbolNum = SymbolAdd(Password);
	if (LetterNum != 0 && IntegerNum != 0 && SymbolNum == 0)
		return 2;
	else if (LetterNum == 10 && IntegerNum != 0 && SymbolNum != 0)
		return 3;
	else if (LetterNum == 20 && IntegerNum != 0 && SymbolNum != 0)
		return 5;
	return 0;
}

void GetPwdSecurityLevel(string Password)//等级判断
{
	int sum = 0;
	sum += LengthAdd(Password);
	sum += LetterAdd(Password);
	sum += IntegerAdd(Password);
	sum += SymbolAdd(Password);
	sum += AwardAdd(Password);
	if (sum >= 90)
		cout << "VERY_SECURE" << endl;
	else if (sum >= 80)
		cout << " SECURE" << endl;
	else if (sum >= 70)
		cout << "VERY_STRONG" << endl;
	else if (sum >= 60)
		cout << "STRONG" << endl;
	else if (sum >= 50)
		cout << "AVERAGE" << endl;
	else if (sum >= 25)
		cout << "WEAK" << endl;
	else
		cout << "VERY_WEAK" << endl;
}


int main()
{
	string str;
	cin >> str;
	GetPwdSecurityLevel(str);

	system("pause");
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值