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

    你可能感兴趣的文章
    node环境:Error listen EADDRINUSE :::3000
    查看>>
    Node的Web应用框架Express的简介与搭建HelloWorld
    查看>>
    Node第一天
    查看>>
    node编译程序内存溢出
    查看>>
    Node读取并输出txt文件内容
    查看>>
    node防xss攻击插件
    查看>>
    noi 1996 登山
    查看>>
    noi 7827 质数的和与积
    查看>>
    NOI-1.3-11-计算浮点数相除的余数
    查看>>
    noi.ac #36 模拟
    查看>>
    NOI2010 海拔(平面图最大流)
    查看>>
    NOIp2005 过河
    查看>>
    NOIP2011T1 数字反转
    查看>>
    NOIP2014 提高组 Day2——寻找道路
    查看>>
    noip借教室 题解
    查看>>
    NOIP模拟测试19
    查看>>
    NOIp模拟赛二十九
    查看>>
    Vue3+element plus+sortablejs实现table列表拖拽
    查看>>
    Nokia5233手机和我装的几个symbian V5手机软件
    查看>>
    non linear processor
    查看>>