import re
def s1(password):
if re.match(r".{,4}$", password):
return 5
if re.match(r".{5,7}$", password):
return 10
if re.match(r".{8,}$", password):
return 25
def s2(password):
if re.match(r"[^a-zA-Z]*$", password):
return 0
if re.match(r"([a-z]*$)|([A-Z]*$)", password):
return 10
if re.match(r".*(?=.*[a-z])(?=.*[A-Z]).*$", password):
return 20
def s3(password):
if re.match(r"[^\d]*$", password):
return 0
if re.match(r"[^\d]*[\d][^\d]*$", password):
return 10
if re.match(r".*[\d]+.*[\d]+.*$", password):
return 20
def s4(password):
if re.match(r"[^!@#$%^&*?]*$", password):
return 0
if re.match(r"[^!@#$%^&*?]*[!@#$%^&*?][^!@#$%^&*?]*$", password):
return 10
if re.match(r".*[!@#$%^&*?]+.*[!@#$%^&*?]+.*$", password):
return 20
def s5(password):
if re.match(r".*(?=.*\d.*$)(?=.*[!@#$%^&*?].*$)(?=.*[a-z].*$)(?=.*[A-Z].*$).*$", password):
return 5
if re.match(r"(?=.*\d.*$)(?=.*[!@#$%^&*?].*$)(?=.*[a-zA-Z].*$).*$", password):
return 3
if re.match(r".*(?=.*[\d].*$)(?=.*[a-zA-Z].*$).*$", password):
return 2
password = input("请输入密码:")
ret = sum((s1(password), s2(password), s3(password), s4(password), s5(password)))
if ret >= 90:
print("非常安全")
elif ret >= 80:
print("安全")
elif ret >= 70:
print("非常强")
elif ret >= 60:
print("强")
elif ret >= 50:
print("一般")
elif ret >= 25:
print("弱")
else:
print("非常弱")