|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
// 判断密码是否为中等强度密码
bool is_password_medium(string password) {
int len = password.length();
if (len < 8) {
return false;
}
bool has_digit = false, has_lower = false, has_upper = false;
for (int i = 0; i < len; i++) {
if (is_digit(password[i])) {
has_digit = true;
}
if (is_lower(password[i])) {
has_lower = true;
}
if (is_upper(password[i])) {
has_upper = true;
}
}
return has_digit && has_lower && has_upper;
}
// 判断密码是否为强密码
bool is_password_strong(string password) {
int len = password.length();
if (len < 8) {
return false;
}
bool has_digit = false, has_lower = false, has_upper = false, has_other = false;
for (int i = 0; i < len; i++) {
if (is_digit(password[i])) {
has_digit = true;
}
else if (is_lower(password[i])) {
has_lower = true;
}
else if (is_upper(password[i])) {
has_upper = true;
}
else {
has_other = true;
}
}
return has_digit && has_lower && has_upper && has_other;
}
代码方法如上,当我在main函数中执行时,输入密码“ADAWDADA1231adadad”本应该输出的时高强度,但是代码输出的是中强度,烦请大佬看看这两个方法该如何修改才能正确执行,题目如下
中强度:密码长度大于等于8个字符,并且包含至少一个数字和一个字母(可以是大小写)
高强度:密码长度大于等于8个字符,并且包含至少一个数字、一个小写字母和一个大写字母 |
|