鱼C论坛

 找回密码
 立即注册
查看: 2178|回复: 4

代码中的问题

[复制链接]
发表于 2023-12-6 03:42:18 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

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个字符,并且包含至少一个数字、一个小写字母和一个大写字母
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2023-12-6 03:49:41 | 显示全部楼层
不行,这样都没办法运行
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-9-30 08:44

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表