编程检查并判断密码字符串的安全强度
password=input("请输入你的密码:")
p=list(password)
x=0
for i in p:
if i == " ":
x=1
if x==1:print("密码格式不对")
elif password.isdigit()==True or password.isalpha()==True:
print("安全强度:弱")
elif password.isalnum()==True:
print("安全强度:中")
else:
print("安全强度:强")
import string
def check(pwd):
if not isinstance(pwd, str) or len(pwd)<6:
return 'not suitable for password'
d = {1:'weak', 2:'below middle', 3:'above middle', 4:'strong'}
r = [False] * 4
for ch in pwd:
if not r[0] and ch in string.digits:
r[0] = True
elif not r[1] and ch in string.ascii_lowercase:
r[1] = True
elif not r[2] and ch in string.ascii_uppercase:
r[2] = True
elif not r[3] and ch in ',.!;?<>':
r[3] = True
return d.get(r.count(True), 'error')
print(check('a2Cdwert,'))