1. # 密码安全性检查代码 2. # 3. # 低级密码要求: 4. # 1. 密码由单纯的数字或字母组成 5. # 2. 密码长度小于等于8位 6. # 7. # 中级密码要求: 8. # 1. 密码必须由数字、字母或特殊字符(仅限:~!@#$%^&*()_=-/,.?<>;:[]{}|\)任意两种组合 9. # 2. 密码长度不能低于8位 10. # 11. # 高级密码要求: 12. # 1. 密码必须由数字、字母及特殊字符(仅限:~!@#$%^&*()_=-/,.?<>;:[]{}|\)三种组合 13. # 2. 密码只能由字母开头 14. # 3. 密码长度不能低于16位
#低级密码要求 #1.密码由纯数字或字母组成 #2.密码长度小于等于8位 '''isbool = True while isbool: pwd1 = input("低级密码测试") if pwd1.isdigit() or pwd1.isalpha(): print("数字或密码") isbool = False else: print("不是数字或字母") isbool = True continue if len(pwd1)<=8: print("长度小于8") isbool = False else: print("长度不正确") isbool = True continue ''' symbols = r'~!@#$%^&*()_=-/,.?<>;:[]{}|\'' chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' nums = '1234567890' isbool = True while isbool: pwd = input("请输入要检查的密码") length = len(pwd) #isspace()是否都为空格 while(pwd.isspace() or length==0): pwd = input("密码不能为空,请重新输入") # 判断长度 0低,1中,2高 flag_len = 0 if(length<=8): flag_len =0 elif(8<length<16): flag_len=1 else: flag_len=2 #判断是否包含特殊字符 flag_con=0 for each in pwd: if each in symbols: flag_con+=1 break #判断是否包含字母 flag_chars=0 for each in pwd: if each in chars: flag_chars +=1 break #判断是否包含数字 flag_num =0 for each in pwd: if each in nums: flag_num+=1 break if (pwd.isdigit() or pwd.isalpha()): flag_num=5 flag_chars=5 print("您的密码安全等级为:") if flag_len==0 or (flag_num==5 and flag_chars==5): print("密码等级低") elif(flag_len==1 and flag_con==1 and flag_chars==1): print("密码等级中级") elif(flag_len==1 and flag_num==1 and flag_chars==1): print("密码等级中级") elif(flag_len==1 and flag_con==1 and flag_num==1): print("密码等级中级") elif(flag_len==2 and flag_con==1 and flag_chars==1): print("密码等级高级") elif(flag_len==2 and flag_num==1 and flag_chars==1): print("密码等级高级") elif(flag_len==2 and flag_con==1 and flag_num==1): print("密码等级高级")