-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpassword.py
More file actions
27 lines (21 loc) · 841 Bytes
/
password.py
File metadata and controls
27 lines (21 loc) · 841 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
27
import string
import random
def generate_password(length=12):
"""Generate a random password of a given length."""
if length < 4:
raise ValueError("Password length should be at least 4 characters.")
password = [
random.choice(string.ascii_uppercase),
random.choice(string.ascii_lowercase),
random.choice(string.digits),
random.choice(string.punctuation)
]
characters = string.ascii_letters + string.digits + string.punctuation
password += [random.choice(characters) for _ in range(length - 4)]
random.shuffle(password)
return ''.join(password)
# 🔽 THIS PART WAS MISSING
if __name__ == "__main__":
length = int(input("Enter password length: "))
pwd = generate_password(length)
print("Generated password:", pwd)