我試圖爲具有以下密碼要求的Active Directory生成隨機密碼:至少8個字符,至少一個特殊字符,至少一個數字,至少一個小寫和至少一個大寫字母。在Python 3中生成需求隨機字符串
通過以下代碼,我可以生成一個隨機密碼並檢查它是否包含特殊字符。生成新密碼直到找到特殊字符。
special_char = "[email protected]%/()=?+.-"
password_string = "".join([random.choice(string.ascii_lowercase + string.ascii_digits + string.ascii_uppercase + special_char) for n in range(8)])
while any(c in password_string for c in special_char) is not True:
password_string = "".join([random.choice(string.ascii_lowercase + string.ascii_digits + string.ascii_uppercase + special_char) for n in range(8)])
的問題,以下是它的唯一檢查的特殊字符,並生成一個新的密碼可能擺脫對方要求假設他們的存在。我怎樣纔能有效地執行AD密碼要求?謝謝你的幫助。
另一種說法:不要使用'(boolean expr)不是真的';使用'not(boolean expr)'。 –