-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathImproved_Password_Generator.py
More file actions
26 lines (19 loc) · 1 KB
/
Improved_Password_Generator.py
File metadata and controls
26 lines (19 loc) · 1 KB
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
import random
import string
def generate_password(length=12, include_uppercase=True, include_digits=True, include_special_chars=True) -> None:
# Define character sets based on user preferences
lowercase_chars = string.ascii_lowercase
uppercase_chars = string.ascii_uppercase if include_uppercase else ''
digit_chars = string.digits if include_digits else ''
special_chars = "!@#$%^&*()_+[]{}|;':,.<>?/" if include_special_chars else ''
# Combine the character sets based on user preferences
all_chars = lowercase_chars + uppercase_chars + digit_chars + special_chars
# Check if at least one character set is selected
if not all_chars:
return "Please include at least one character set in the password."
# Generate the password
password = ''.join(random.choice(all_chars) for _ in range(length))
return password
# Example usage:
password = generate_password(length=16, include_uppercase=True, include_digits=True, include_special_chars=True)
print(password)