鱼C论坛

 找回密码
 立即注册
查看: 964|回复: 0

[原创] 课后作业14讲:密码安全性检查代码

[复制链接]
发表于 2022-8-29 23:31:35 | 显示全部楼层 |阅读模式

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

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

x
本帖最后由 MaxFireGun 于 2022-8-29 23:34 编辑
  1. check_mark='~!@#$%^&*()_=-/,.?<>;:[]{}|\\'\

  2. # print(check_mark)

  3. while True:

  4.     code = input('Please input ur code here:')
  5.    
  6.     code_len = len(code)
  7.    
  8.     Flag = True
  9.    
  10.     f_check_list=[0,0,0] #[alpha, number, mark]
  11.    
  12.     for i in code:
  13.         if i.isalpha():
  14.             f_check_list[0] += 1
  15.         elif i.isdigit():
  16.             f_check_list[1] += 1
  17.         elif i in check_mark:
  18.             f_check_list[2] += 1
  19.         else:
  20.             print('Ur code is not standard. Some symbols are not allowed! Please check the code rules as follow: ****')
  21.             Flag = False
  22.             break  

  23. ######Check whether there is symbol that is not included in the check_mark######   
  24.     if Flag == False:
  25.         continue   
  26.     else:
  27.         pass
  28. ########################################################################


  29.     #print(f_check_list)
  30.    
  31.     if code_len <= 8 and ((f_check_list[0] > 0 or f_check_list[1] > 0) and f_check_list[2] == 0):
  32.         print('Ur code is in low security level')
  33.         break
  34.    
  35.     elif code_len > 8 and int(bool(f_check_list[0])) + int(bool(f_check_list[1])) + int(bool(f_check_list[2])) == 2:
  36.         print('Ur code is in medium security level')
  37.         break
  38.         
  39.     elif code_len >= 16 and code[0].isalpha() and (f_check_list[0] > 0 and f_check_list[1] > 0 and f_check_list[2] > 0):
  40.         print('Ur code is in high security level')
  41.         break
  42.         
  43.     else:
  44.         print('Ur code is not standard. Please check the code rules as follow: *********')
复制代码


课后作业说明:
1. 对于满足题目中所给要求的密码,会给出相应的密码安全等级,然后跳出循环。
2.对于不符号不在列表里的,会及时跳出for和while循环,节约计算时间。同时给出'Ur code is not standard. Some symbols are not allowed! Please check the code rules as follow: ****'的提示,并让客户继续输入密码。
2. 对于不满足所有三种要求的密码,会给出'Ur code is not standard, Please check the code rules as follow: balablabla'的提示,并继续让客户输入密码。
3. ‘#’后面的是在测试的过程中用来打印相应的数据,查看程序跑得是否正确,可以忽略。

Beer! Cheers!!


想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-20 09:41

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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