Here's a simple code snippet that generates a random password that includes at least two uppercase letters using the string
and random
modules in Python:
main.py605 chars20 lines
The generate_password()
function uses the random.choice()
method to randomly select characters from the character sets for uppercase and lowercase letters, digits, and symbols. It then checks if there are at least two uppercase letters in the generated password using a regular expression pattern ("[A-Z]"
) and the re.findall()
method. If there are at least two uppercase letters, the function returns the password. Otherwise, it generates another password until there are at least two uppercase letters.
gistlibby LogSnag