我的代碼正在運行,但定義什麼使得強密碼的第一行代碼會導致代碼的其餘部分無效返回。例如,當第一行代碼正在搜索一個數字字符時,其中的任何代碼都會導致代碼在滿足要求時不打印消息。如果我從尋找一個數字,以尋找一個資本或小寫字符改變它,那麼任何編碼以後也不會,如果代碼需要尋找資金或小寫等功能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