0% found this document useful (0 votes)
5 views

password-generator

Uploaded by

sirbaala
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

password-generator

Uploaded by

sirbaala
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

import random

# Defining character sets manually


digits = "0123456789"
letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
special_chars = "!@#$%^&*()_+-=[]{}|;:’,.<>?/"

# Getting password length


lent= int(input("Enter password length: "))

print("""Choose character set for password from these:


1. Digits
2. Letters
3. Special characters
4. Exit""")

charList = ""

# Getting character set for password


while True:
cho = int(input("Pick a number: "))
if cho == 1:
# Adding digits to possible characters
charList += letters
elif cho == 2:
# Adding letters to possible characters
charList += digits
elif cho == 3:
# Adding special characters to possible characters
charList += special_chars
elif cho == 4:
break
else:
print("Please pick a valid option!")

if not charList:
print("No character set selected. Exiting...")
else:
pwd = ""
for i in range(lent):
# Picking a random character from our character list
randomchar = charList[random.randint(0, len(charList) - 1)]
# Appending a random character to password
pwd += randomchar

# Printing password as a string


print("The random password is: ", pwd)

You might also like