Created
July 27, 2023 02:10
-
-
Save graydenshand/96353d17e97a103f5035e14be2591a01 to your computer and use it in GitHub Desktop.
Generate a secure password, from https://docs.python.org/3/library/secrets.html#recipes-and-best-practices
This file contains 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 argparse | |
import secrets | |
import string | |
if __name__ == "__main__": | |
parser = argparse.ArgumentParser() | |
parser.add_argument("-s", "--symbols", help="Include symbols in password", action="store_true") | |
parser.add_argument("-l", "--length", type=int, default=16, help="Password length") | |
args = parser.parse_args() | |
alphabet = string.ascii_letters + string.digits | |
if args.symbols: | |
alphabet += string.punctuation | |
print(''.join(secrets.choice(alphabet) for _ in range(args.length))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment