Files
troupe-standup/wizard-work/spark/generate_password.py
T

31 lines
1.1 KiB
Python

#!/usr/bin/env python3
"""Generate cryptographically secure random passwords."""
import secrets
import string
import argparse
def generate_password(length: int = 16, include_symbols: bool = True) -> str:
"""Generate a secure random password.
Args:
length: Password length (minimum 8)
include_symbols: Include special characters
Returns:
Generated password string
"""
if length < 8:
raise ValueError("Password length must be at least 8 characters")
chars = string.ascii_letters + string.digits
if include_symbols:
chars += "!@#$%^&*()-_=+[]{}|;:,.<>?"
return ''.join(secrets.choice(chars) for _ in range(length))
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Generate secure random passwords")
parser.add_argument("-l", "--length", type=int, default=16, help="Password length")
parser.add_argument("-s", "--symbols", action="store_true", help="Include symbols")
args = parser.parse_args()
print(generate_password(args.length, args.symbols))