import random import string import questionary def generate_password(length,use_upper=True,use_lower=True,use_digits=True,use_symbols=True): characters="" if use_upper:characters+=string.ascii_uppercase if use_lower:characters+=string.ascii_lowercase if use_digits:characters+=string.ascii_uppercase if use_symbols:characters+=string.punctuation characterslist=list(characters) password="" if not characters: return "" for i in range(length): password+=random.choice(characterslist) return password def main(): print("Bitwarden password generator clone") length=questionary.text("How long?",validate=lambda text: True if text.isdigit() else "Please enter a valid number").ask() use_upper=questionary.confirm("Use uppercase?").ask() use_lower=questionary.confirm("Use lowercase?").ask() use_digits=questionary.confirm("Use digits?").ask() use_symbols=questionary.confirm("Use symbols?").ask() pw=generate_password(int(length),use_upper,use_lower,use_digits,use_symbols) if pw: print(pw) else: print("You didn't choose anything to put in, here's your password anyway: \"\"") if __name__=="__main__": main()