Skip to content

Create passwordgenerator.py #182

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions code/code/cryptography/src/password_generator/passwordgenerator.py
Original file line number Diff line number Diff line change
@@ -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---------")