博客
关于我
L1-6 检查密码 (15分)
阅读量:342 次
发布时间:2019-03-04

本文共 1778 字,大约阅读时间需要 5 分钟。

密码合法性检查功能开发指南

功能概述

该模块负责对用户注册密码的合法性进行检查,确保密码符合网站设定的安全规则。

输入格式

  • 该模块接受一个正整数N,表示待检查的密码数量
  • 接下来的N行分别为待检查的密码字符串
  • 每个密码字符串满足不超过80个字符且为非空字符串
  • 输出格式

    对每个密码字符串,输出以下类型的反馈信息之一:

  • 如果密码合法,输出:“Your password is wan mei。”
  • 如果密码长度不足6个字符,输出:“Your password is tai duan le。”
  • 如果密码长度符合要求但包含非法字符,输出:“Your password is tai luan le。”
  • 如果密码长度符合要求但仅包含数字,输出:“Your password needs shu zi。”
  • 如果密码长度符合要求但仅包含字母,输出:“Your password needs zi mu。”
  • 实现细节

  • 密码长度检查:首先验证密码长度是否≥6个字符
  • 合法字符检查:允许字母(大小写)、数字和小数点
  • 必要字符组合检查:确保密码中既有字母又有数字
  • 样例分析

    输入样例

    5123szheshi.wodepw1234.5678WanMei23333pass*word.6

    输出样例

    Your password is tai duan le.Your password needs shu zi.Your password needs zi mu.Your password is wan mei.Your password is tai luan le.

    开发注意事项

  • 输入处理:注意密码可能包含空格字符,应使用适当的读取方式
  • 正则表达式优化:可使用正则表达式简化合法字符检查
  • 性能优化:确保在处理大量密码时依然保持高效率
  • 常见问题

  • 为什么密码长度检查放在第一位?
    • 由于密码长度是基本的安全要求,优先检查可以提升效率
  • 是否需要考虑特殊符号?
    • 根据要求不需要,仅允许字母、数字和小数点
  • 技术实现

    #include 
    #include
    #include
    int main() { int n; scanf("%d\n", &n); while (n--) { char password[100]; gets(password); if (strlen(password) < 6) { printf("Your password is tai duan le.\n"); continue; } int has_letter = 0, has_digit = 0; for (int i = 0; password[i]; i++) { if (isdigit(password[i])) has_digit = 1; else if (isalpha(password[i])) has_letter = 1; else if (password[i] == '.') continue; else { printf("Your password is tai luan le.\n"); goto loop; } } if (!has_letter && has_digit) { printf("Your password needs zi mu.\n"); } else if (has_letter && !has_digit) { printf("Your password needs shu zi.\n"); } else { printf("Your password is wan mei.\n"); } loop:; }}

    转载地址:http://vpwe.baihongyu.com/

    你可能感兴趣的文章
    NSOperation基本操作
    查看>>
    NSRange 范围
    查看>>
    NSSet集合 无序的 不能重复的
    查看>>
    NT AUTHORITY\NETWORK SERVICE 权限问题
    查看>>
    NT symbols are incorrect, please fix symbols
    查看>>
    ntko web firefox跨浏览器插件_深度比较:2019年6个最好的跨浏览器测试工具
    查看>>
    ntko文件存取错误_苹果推送 macOS 10.15.4:iCloud 云盘文件夹共享终于来了
    查看>>
    ntpdate 通过外网同步时间
    查看>>
    NTP配置
    查看>>
    NUC1077 Humble Numbers【数学计算+打表】
    查看>>
    Nuget~管理自己的包包
    查看>>
    nullnullHuge Pages
    查看>>
    Numix Core 开源项目教程
    查看>>
    NumPy 或 Pandas:将数组类型保持为整数,同时具有 NaN 值
    查看>>
    numpy 数组 dtype 在 Windows 10 64 位机器中默认为 int32
    查看>>
    numpy 用法
    查看>>
    Numpy 科学计算库详解
    查看>>
    Numpy.ndarray对象不可调用
    查看>>
    Numpy如何使用np.umprod重写range函数中i的python
    查看>>
    numpy数组索引-ChatGPT4o作答
    查看>>