Skip to content

Instantly share code, notes, and snippets.

@Xinayder
Last active December 3, 2016 18:34
Show Gist options
  • Save Xinayder/7c1b0b074595d13c446c953f13184f6e to your computer and use it in GitHub Desktop.
Save Xinayder/7c1b0b074595d13c446c953f13184f6e to your computer and use it in GitHub Desktop.
import string
import random
import argparse
def generate_password(size=8, chars=string.ascii_letters + string.digits, punctuation=False):
if punctuation:
chars = chars + "!@#$*?"
return ''.join(random.SystemRandom().choice(chars) for _ in range(size))
def main():
arg_parser = argparse.ArgumentParser(prog='generate-password')
arg_parser.add_argument('-l', '--length', required=False, metavar='<password length>', dest='password_length', type=int, default=8, help='determine how many characters the generated password will have.')
arg_parser.add_argument('-p', '--punctuation', required=False, action='store_true', dest='use_punctuation', default=False, help='determine if the generated password should include punctuation characters.')
args = arg_parser.parse_args()
password = generate_password(size=args.password_length, punctuation=args.use_punctuation)
print("Your generated password: %s" % password)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment