-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpassword_generator.py
More file actions
26 lines (22 loc) · 832 Bytes
/
password_generator.py
File metadata and controls
26 lines (22 loc) · 832 Bytes
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
def generate_password(length=12):
"""Generates a random password of the specified length."""
if length < 8:
raise ValueError("Password length should be at least 8 characters.")
if length > 50:
raise ValueError("Password length should not exceed 50 characters.")
letters = "abcdefghijklmnopqrstuvwxyz"
digits = "0123456789"
symbols = "!@#$%^&*()"
characters = letters + letters.upper() + digits + symbols
password = ''
for _ in range(length):
password += random.choice(characters)
return password
if __name__ == "__main__":
try:
length = int(input("Enter the password length (min: 8, max 50): "))
password = generate_password(length)
print(f"Generated Password: {password}")
except ValueError as e:
print(e)