|
发表于 2023-12-6 03:42:45
|
显示全部楼层
问题出在判断是否包含数字、小写字母和大写字母的地方。目前的代码中,通过调用 is_digit()、is_lower() 和 is_upper() 函数来判断,但是这些函数需要传入一个字符,并且返回的是布尔值,而不是判断整个字符串是否包含这些字符。
所以,你需要修改这部分代码,使用循环遍历整个字符串,判断是否包含数字、小写字母和大写字母。以下是修改后的代码:
// 判断密码是否为中等强度密码
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 (isdigit(password[i])) { // 使用isdigit()函数判断是否为数字
has_digit = true;
}
if (islower(password[i])) { // 使用islower()函数判断是否为小写字母
has_lower = true;
}
if (isupper(password[i])) { // 使用isupper()函数判断是否为大写字母
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 (isdigit(password[i])) { // 使用isdigit()函数判断是否为数字
has_digit = true;
}
else if (islower(password[i])) { // 使用islower()函数判断是否为小写字母
has_lower = true;
}
else if (isupper(password[i])) { // 使用isupper()函数判断是否为大写字母
has_upper = true;
}
else {
has_other = true;
}
}
return has_digit && has_lower && has_upper && has_other;
}
这样修改后的代码会在循环中遍历字符串的每个字符,并针对每个字符进行判断,从而正确判断密码的强度。
以上回复来自 -- ChatGPT(FishC官方接口),如未能正确解答您的问题,请继续追问。 |
|