-
Notifications
You must be signed in to change notification settings - Fork 306
/
Password Generator
25 lines (20 loc) · 961 Bytes
/
Password Generator
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
import random
import string
def generate_password(length, use_uppercase, use_digits, use_special):
characters = string.ascii_lowercase # Start with lowercase letters
if use_uppercase:
characters += string.ascii_uppercase # Add uppercase letters
if use_digits:
characters += string.digits # Add digits
if use_special:
characters += string.punctuation # Add special characters
password = ''.join(random.choice(characters) for _ in range(length))
return password
# User input
length = int(input("Enter the desired password length: "))
use_uppercase = input("Include uppercase letters? (y/n): ").lower() == 'y'
use_digits = input("Include digits? (y/n): ").lower() == 'y'
use_special = input("Include special characters? (y/n): ").lower() == 'y'
# Generate and display the password
password = generate_password(length, use_uppercase, use_digits, use_special)
print(f"Your generated password is: {password}")