From 3a79e1ac1b95d5cf3ba4f526f0a6cc8fa91bee12 Mon Sep 17 00:00:00 2001 From: Jerry Zhu <54565411+Bobliuuu@users.noreply.github.com> Date: Wed, 5 Oct 2022 01:00:57 -0400 Subject: [PATCH] Create passwordgenerator.py --- .../password_generator/passwordgenerator.py | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 code/code/cryptography/src/password_generator/passwordgenerator.py diff --git a/code/code/cryptography/src/password_generator/passwordgenerator.py b/code/code/cryptography/src/password_generator/passwordgenerator.py new file mode 100644 index 0000000..e82ea25 --- /dev/null +++ b/code/code/cryptography/src/password_generator/passwordgenerator.py @@ -0,0 +1,32 @@ +# This program will generate a strong password using cryptography principles + +# Import secrets and string module +# The string module defines the alphabet, and the secret module generates cryptographically sound random numbers +import secrets +import string + +# Define the alphabet to be digits, letters, and special characters +letters = string.ascii_letters +digits = string.digits +special = string.punctuation +alphabet = letters + digits + special + +# Set the password length +while True: + try: + password_length = int(input("Please enter the length of your password: ")) + break + except ValueError: + print("Please enter an integer length.") + +# Generates strong password with at least one special character and one digit +while True: + password = '' + for i in range(password_length): + password += ''.join(secrets.choice(alphabet)) + if (any(char in special for char in password) and any(char in digits for char in password)): + break + +print("--------Your Password Has Been Generated---------") +print(password) +print("--------Make Sure To Keep Your Password Safe---------")