Skip to content

Instantly share code, notes, and snippets.

@beatorizu
Last active July 4, 2021 18:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beatorizu/6ebf6a97be28951ddcb38e9ef8cef334 to your computer and use it in GitHub Desktop.
Save beatorizu/6ebf6a97be28951ddcb38e9ef8cef334 to your computer and use it in GitHub Desktop.
A simple code to generate passwords
-r requirements.txt
autopep8
flake8
# Reference https://stackoverflow.com/a/39596292/5298722
import secrets
import string
import click
import pyperclip
@click.command()
@click.option('--lenght', '-l', default=8, help='The lenght of the password')
@click.option('--digits', '-d', default=False, help='Include digits [0-9]', is_flag=True)
@click.option('--punctuation', '-p', default=False, help='Include punctuation', is_flag=True)
def generate_password(lenght, digits, punctuation):
"""Simple code to generate passwords"""
chars = string.ascii_letters + string.digits * digits + string.punctuation * punctuation
password = ''.join(secrets.choice(chars) for _ in range(lenght))
pyperclip.copy(password)
if __name__ == '__main__':
generate_password()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment