Last active
December 3, 2016 18:34
-
-
Save Xinayder/7c1b0b074595d13c446c953f13184f6e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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