-
Notifications
You must be signed in to change notification settings - Fork 87
/
strongpasswordgenerator.py
32 lines (28 loc) · 1.03 KB
/
strongpasswordgenerator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# 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---------")