博客
关于我
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/

    你可能感兴趣的文章
    npm install 报错 Failed to connect to github.com port 443 的解决方法
    查看>>
    npm install 报错 fatal: unable to connect to github.com 的解决方法
    查看>>
    npm install 报错 no such file or directory 的解决方法
    查看>>
    npm install 权限问题
    查看>>
    npm install报错,证书验证失败unable to get local issuer certificate
    查看>>
    npm install无法生成node_modules的解决方法
    查看>>
    npm install的--save和--save-dev使用说明
    查看>>
    npm node pm2相关问题
    查看>>
    npm run build 失败Compiler server unexpectedly exited with code: null and signal: SIGBUS
    查看>>
    npm run build报Cannot find module错误的解决方法
    查看>>
    npm run build部署到云服务器中的Nginx(图文配置)
    查看>>
    npm run dev 和npm dev、npm run start和npm start、npm run serve和npm serve等的区别
    查看>>
    npm run dev 报错PS ‘vite‘ 不是内部或外部命令,也不是可运行的程序或批处理文件。
    查看>>
    npm scripts 使用指南
    查看>>
    npm should be run outside of the node repl, in your normal shell
    查看>>
    npm start运行了什么
    查看>>
    npm WARN deprecated core-js@2.6.12 core-js@<3.3 is no longer maintained and not recommended for usa
    查看>>
    npm 下载依赖慢的解决方案(亲测有效)
    查看>>
    npm 安装依赖过程中报错:Error: Can‘t find Python executable “python“, you can set the PYTHON env variable
    查看>>
    npm.taobao.org 淘宝 npm 镜像证书过期?这样解决!
    查看>>