博客
关于我
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介绍以及常用命令
    查看>>
    NPM使用前设置和升级
    查看>>
    npm入门,这篇就够了
    查看>>
    npm切换到淘宝源
    查看>>
    npm切换源淘宝源的两种方法
    查看>>
    npm前端包管理工具简介---npm工作笔记001
    查看>>
    npm包管理深度探索:从基础到进阶全面教程!
    查看>>
    npm升级以及使用淘宝npm镜像
    查看>>
    npm发布包--所遇到的问题
    查看>>
    npm发布自己的组件UI包(详细步骤,图文并茂)
    查看>>
    npm和package.json那些不为常人所知的小秘密
    查看>>
    npm和yarn清理缓存命令
    查看>>
    npm和yarn的使用对比
    查看>>
    npm如何清空缓存并重新打包?
    查看>>
    npm学习(十一)之package-lock.json
    查看>>
    npm安装 出现 npm ERR! code ETIMEDOUT npm ERR! syscall connect npm ERR! errno ETIMEDOUT npm ERR! 解决方法
    查看>>
    npm安装crypto-js 如何安装crypto-js, python爬虫安装加解密插件 找不到模块crypto-js python报错解决丢失crypto-js模块
    查看>>
    npm安装教程
    查看>>
    npm报错Cannot find module ‘webpack‘ Require stack
    查看>>
    npm报错Failed at the node-sass@4.14.1 postinstall script
    查看>>