-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPassword Generator.py
34 lines (27 loc) · 1.2 KB
/
Password Generator.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
33
34
import random
import string
def generate_password(length=12, uppercase=True, lowercase=True, digits=True, special_chars=True):
characters = ""
if uppercase:
characters += string.ascii_uppercase
if lowercase:
characters += string.ascii_lowercase
if digits:
characters += string.digits
if special_chars:
characters += string.punctuation
if not any([uppercase, lowercase, digits, special_chars]):
print("At least one of the parameters uppercase, lowercase, digits, special_chars must be True.")
password = ''.join(random.choice(characters) for _ in range(length))
return password
def main():
print("Password Generator")
length = int(input("Enter length of password: "))
uppercase = input("Include capital letters? (Y/N): ").upper() == 'Y'
lowercase = input("Do you include lowercase letters? (Y/N): ").upper() == 'Y'
digits = input("Do you want to include numbers? (Y/N): ").upper() == 'Y'
special_chars = input("Include special characters? (Y/N): ").upper() == 'Y'
password = generate_password(length, uppercase, lowercase, digits, special_chars)
print("Created Password:", password)
if __name__ == "__main__":
main()