Skip to content

Instantly share code, notes, and snippets.

@glynos
Last active June 15, 2017 15:12
Show Gist options
  • Save glynos/17787c8df02382cd7169cd4220607580 to your computer and use it in GitHub Desktop.
Save glynos/17787c8df02382cd7169cd4220607580 to your computer and use it in GitHub Desktop.
import sys
import argparse
import random
import pyperclip
__chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
__digits = "1234567890"
__symbols = "!@#$%^&*()_-+={[}]|\\:;\"\'<,>.?/"
def generate_password(length, use_digits=True, use_symbols=True):
chars = __chars
if use_digits:
chars += __digits
if use_symbols:
chars += __symbols
return "".join(
[ chars[random.randrange(len(chars))] for i in range(length) ])
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument(
'--length',
type=int,
default=12,
help="The length of the generated password.")
parser.add_argument(
'--use_digits', '-d', action='store_true', default=False)
parser.add_argument(
'--use_symbols', '-s', action='store_true', default=False)
args = parser.parse_args()
pyperclip.copy(generate_password(
length=args.length,
use_digits=args.use_digits,
use_symbols=args.use_symbols))
print("The password has been copied to the clipboard.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment