"""Password utils.""" import secrets import string import config def generate_random_password(): """Generate a complex random password.""" password = '' while len(password) < config.PASSWORD_MIN_LENGTH: upper = secrets.choice(string.ascii_uppercase) lower = secrets.choice(string.ascii_lowercase) num = secrets.choice(string.digits) symbol = secrets.choice('#$%^()') chars = list(upper + lower + num + symbol) secrets.SystemRandom().shuffle(chars) password += ''.join(chars) return password