我的代码正在运行,但定义什么使得强密码的第一行代码会导致代码的其余部分无效返回。例如,当第一行代码正在搜索一个数字字符时,其中的任何代码都会导致代码在满足要求时不打印消息。如果我从寻找一个数字,以寻找一个资本或小写字符改变它,那么任何编码以后也不会,如果代码需要寻找资金或小写等功能re.search密码检查错误
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.")
密码的长度是否会影响您在此处提供的强度等级? – shuttle87 2014-11-09 00:54:53
如果密码在6到12个字符之间,那么只会测试强度。然而,长度并不影响力量,它只是它具有的字符。 – user3292752 2014-11-09 00:57:08