函数main()接受一个任意字符串pwd,要求返回该字符串作为密码时的安全强度。
def main(pwd):
1)如果长度小于6直接判断为弱密码并返回'weak';2)如果只包含数字、小写字母、大写字母、英文半角表达符号(只考虑逗号和句号)这4类符号中的1种,就判断为弱密码并返回'weak';3)如果只包含上述4种符号中的2种,判断为中低强度并返回'below_middle';4)如果只包含上述4种符号中的3种,判断为中高强度并返回'above_middle';5)如果同时包含上述4种符号,判断为强密码并返回'strong';6)其他任意情况都认为是弱密码并返回'weak'。
from string import punctuation
def main(pwd:str):
if len(pwd)<6:return 'weak'
num=up=low=pun=False
for i in pwd:
if i.isnumeric():num=True
if i.isupper():up=True
if i.islower():low=True
if i in punctuation:pun=True
res=num+up+low+pun
if res>3:return 'strong'
elif res>2:return 'above_middle'
elif res>1:return 'below_middle'
else:return 'weak'
print(main(input('Please input your password:')))