课后作业14讲:密码安全性检查代码
本帖最后由 MaxFireGun 于 2022-8-29 23:34 编辑check_mark='~!@#$%^&*()_=-/,.?<>;:[]{}|\\'\
# print(check_mark)
while True:
code = input('Please input ur code here:')
code_len = len(code)
Flag = True
f_check_list= #
for i in code:
if i.isalpha():
f_check_list += 1
elif i.isdigit():
f_check_list += 1
elif i in check_mark:
f_check_list += 1
else:
print('Ur code is not standard. Some symbols are not allowed! Please check the code rules as follow: ****')
Flag = False
break
######Check whether there is symbol that is not included in the check_mark######
if Flag == False:
continue
else:
pass
########################################################################
#print(f_check_list)
if code_len <= 8 and ((f_check_list > 0 or f_check_list > 0) and f_check_list == 0):
print('Ur code is in low security level')
break
elif code_len > 8 and int(bool(f_check_list)) + int(bool(f_check_list)) + int(bool(f_check_list)) == 2:
print('Ur code is in medium security level')
break
elif code_len >= 16 and code.isalpha() and (f_check_list > 0 and f_check_list > 0 and f_check_list > 0):
print('Ur code is in high security level')
break
else:
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!!
页:
[1]