鱼C论坛

 找回密码
 立即注册
查看: 2114|回复: 2

第014讲 写一个密码安全性检查的代码

[复制链接]
发表于 2020-2-18 18:42:48 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 施工队员 于 2020-2-18 18:47 编辑

请问我这样写代码跟答案代码看起来差别很大,在功能上会有什么影响吗?


  1. temp = input("请输入需要检查的密码组合:")
  2. length = len(temp)
  3. if length <= 8:
  4.     print('''您的密码安全评定级别为:低
  5. 请按照以下方式提升您的密码安全级别:
  6. 1.密码必须由数字、字母及特殊字符三种组合
  7. 2.密码只能由字母开头
  8. 3.密码长度不能低于16位''')
  9. elif temp.isnumeric():
  10.     print('''您的密码安全评定级别为:低
  11. 请按照以下方式提升您的密码安全级别:
  12. 1.密码必须由数字、字母及特殊字符三种组合
  13. 2.密码只能由字母开头
  14. 3.密码长度不能低于16位''')
  15. elif temp.isalpha():
  16.     print('''您的密码安全评定级别为:低
  17. 请按照以下方式提升您的密码安全级别:
  18. 1.密码必须由数字、字母及特殊字符三种组合
  19. 2.密码只能由字母开头
  20. 3.密码长度不能低于16位''')
  21. elif 8 <= length <= 16:
  22.     print('''您的密码安全评定级别为:中
  23. 请按照以下方式提升您的密码安全级别:
  24. 1.密码必须由数字、字母及特殊字符三种组合
  25. 2.密码只能由字母开头
  26. 3.密码长度不能低于16位''')
  27. elif temp.isalnum():
  28.     print('''您的密码安全评定级别为:中
  29. 请按照以下方式提升您的密码安全级别:
  30. 1.密码必须由数字、字母及特殊字符三种组合
  31. 2.密码只能由字母开头
  32. 3.密码长度不能低于16位''')
  33. elif temp.startswith('1') or temp.startswith('2') or temp.startswith('3') or \
  34.      temp.startswith('4') or temp.startswith('5') or temp.startswith('6') or \
  35.      temp.startswith('7') or temp.startswith('8') or temp.startswith('9') or \
  36.      temp.startswith('~') or temp.startswith('!') or temp.startswith('@') or \
  37.      temp.startswith('#') or temp.startswith('
  38. ) or temp.startswith('%') or \
  39.      temp.startswith('^') or temp.startswith('&') or temp.startswith('*') or \
  40.      temp.startswith('(') or temp.startswith(')') or temp.startswith('_') or \
  41.      temp.startswith('=') or temp.startswith('-') or temp.startswith('/') or \
  42.      temp.startswith(',') or temp.startswith('.') or temp.startswith('?') or \
  43.      temp.startswith('<') or temp.startswith('>') or temp.startswith(';') or \
  44.      temp.startswith(':') or temp.startswith('[') or temp.startswith(']') or \
  45.      temp.startswith('{') or temp.startswith('}') or temp.startswith('|') or \
  46.      temp.startswith('\\'):
  47.     print('''您的密码安全评定级别为:中
  48. 请按照以下方式提升您的密码安全级别:
  49. 1.密码必须由数字、字母及特殊字符三种组合
  50. 2.密码只能由字母开头
  51. 3.密码长度不能低于16位''')

  52. else:
  53.     print('''您的密码安全级别评定为:高
  54. 请继续保持''')

复制代码

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2020-2-18 18:49:07 | 显示全部楼层
为什么我发的时候temp.startswith('$')没有问题,发出来$就不见了,变成换行了?
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-2-18 18:52:29 | 显示全部楼层
如果运行之后没问题,那功能上应该就不受什么影响吧
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2026-1-22 15:13

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表