【发布时间】:2015-01-05 13:46:54
【问题描述】:
我的代码正在运行,但定义强密码的第一行代码导致其余代码返回为空。例如,当第一行代码正在搜索一个数字字符时,从那里开始的任何代码都会导致代码在满足要求的情况下不打印消息。如果我将它从搜索数字更改为搜索大写或小写字符,那么如果代码需要查找大写或小写等,则之后的任何编码都将不起作用。
import re
password = str(input("Please enter the password you wish to test the strength of.\n"))
if re.search(r'[0-9]', password):
if re.search(r'[A-Z]', password):
if re.search(r'[a-z]', password):
print("Your password strength is STRONG.")
elif re.search(r'[a-z]', password) and re.search(r'[A-Z]', password):
print("Your password strength is MEDIUM.")
elif re.search(r'[0-9]', password) and re.search(r'[A-Z]', password):
print("Your password strength is MEDIUM.")
elif re.search(r'[a-z]', password) and re.search(r'[0-9]', password):
print("Your password strength is MEDIUM.")
elif re.search(r'[A-Z]', password) or re.search(r'[a-z]', password) or re.search(r'[0-9]', password):
print("Your password strength is WEAK.")
【问题讨论】:
-
密码长度是否会影响您在此处给出的强度等级?
-
如果密码在 6 到 12 个字符之间,则只测试强度。但是长度不影响强度,它只是它具有的字符。
标签: python regex passwords character