Generating Random Passwords with Customizable Strength
Description
This Python script generates random passwords of varying lengths and complexities. Users can specify the desired length and inclusion of uppercase letters, numbers, and symbols.
Code Snippet
import random
import string
def generate_password(length, uppercase=True, numbers=True, symbols=True):
characters = string.ascii_lowercase
if uppercase:
characters += string.ascii_uppercase
if numbers:
characters += string.digits
if symbols:
characters += string.punctuation
password = ''.join(random.choice(characters) for i in range(length))
return password
# Example usage:
password = generate_password(12, uppercase=True, numbers=True, symbols=True)
print(f"Generated Password: {password}")
password = generate_password(8, uppercase=False, numbers=True, symbols=False)
print(f"Generated Password: {password}")