我正在为学校编写一个程序,该程序应该检查密码的强度并将它们分成 3 个参数。我在识别强字符中的特殊字符以对强字符进行分类时遇到问题。任何帮助是极大的赞赏。
#include <iostream>
#include <string>
using namespace std;
int main()
{
string input;
bool complete = false;
bool hasUpper = false;
bool hasLower = false;
bool hasDigit = false;
bool specialChar = false;
int count;
char special = 'a';
do
{
cout << endl << "Enter a password to rate its strength. Enter q to quit." << endl;
cin >> input;
for(count =0; count < input.size(); count++)
{
if( islower(input[count]) )
hasLower = true;
if( isupper(input[count]) )
hasUpper = true;
if( isdigit(input[count]) )
hasDigit = true;
special = input.find_first_not_of("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 ");
if (special != 'a')
specialChar = true;
}
if (hasLower && hasUpper && hasDigit && specialChar && (count >= 8))
{
cout << "Strong" << endl;
}
else if((hasLower || hasUpper) && hasDigit && (count >= 6))
{
cout << "Moderate" << endl;
}
else
{
cout << "Weak" << endl;
}
if (input == "q") complete = true;
}while (!complete);
return 0;
}