安全密码(字符串)

#include <stdio.h>
#include <stdbool.h>
#include <string.h>
bool is_secure_password(const char* password);
int main()
{
    int M;
    char password[51];
    // 读取输入中的密码数量 M
    scanf("%d", &M);
    // 处理每个密码
    for (int i = 0; i < M; ++i)
    {
        // 读取密码
        scanf("%s", password);

        // 检查密码是否安全并输出结果
        if (is_secure_password(password))
        {
            printf("YES\n");
        }
        else
        {
            printf("NO\n");
        }
    }
    return 0;
}
// 函数定义
bool is_secure_password(const char* password)
{
    // 检查密码长度
    int len = strlen(password);
    if (8 <= len && len <= 16)
    {
        // 检查密码字符类别
        bool categories[4] = { false };  // 大写字母、小写字母、数字、特殊符号
        for (int i = 0; i < len; ++i) {
            char current = password[i];
            if ('A' <= current && current <= 'Z')
            {
                categories[0] = true;
            }
            else if ('a' <= current && current <= 'z')
            {
                categories[1] = true;
            }
            else if ('0' <= current && current <= '9')
            {
                categories[2] = true;
            }
            else if (strchr("~!@#$%^&", current) != NULL)
            {
                categories[3] = true;
            }
        }
        // 判断密码是否包含至少三组字符类别
        if (categories[0] + categories[1] + categories[2] + categories[3] >= 3)
        {
            return true;
        }
    }
    return false;
}

相关推荐

  1. 密码安全攻击分类

    2023-12-18 01:48:01       41 阅读
  2. 安全防御之密码技术

    2023-12-18 01:48:01       31 阅读
  3. 如何取安全密码

    2023-12-18 01:48:01       14 阅读
  4. mysql安装_改密码_找回密码

    2023-12-18 01:48:01       4 阅读
  5. Ubuntu安装MySQL未设置密码/修改密码/删除密码

    2023-12-18 01:48:01       40 阅读

最近更新

  1. TCP协议是安全的吗?

    2023-12-18 01:48:01       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2023-12-18 01:48:01       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2023-12-18 01:48:01       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2023-12-18 01:48:01       20 阅读

热门阅读

  1. 六大设计原则

    2023-12-18 01:48:01       33 阅读
  2. 第16课 SQL入门之更新和删除数据

    2023-12-18 01:48:01       44 阅读
  3. c# 数组删除

    2023-12-18 01:48:01       38 阅读
  4. 外部函数接口FFI

    2023-12-18 01:48:01       37 阅读
  5. LeetCode 15 三数之和

    2023-12-18 01:48:01       39 阅读
  6. 1131 - 删除指定字符

    2023-12-18 01:48:01       38 阅读