-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpassgen.py
More file actions
27 lines (22 loc) · 755 Bytes
/
Copy pathpassgen.py
File metadata and controls
27 lines (22 loc) · 755 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 random
import string
def generate_password(length):
if length < 4:
print("Password should be at least 4 characters.")
return ""
# Create character pools
all_chars = string.ascii_letters + string.digits + string.punctuation
# Randomly choose characters
password = ''.join(random.choice(all_chars) for _ in range(length))
return password
def main():
print("🔐 Welcome to the Password Generator!")
try:
length = int(input("Enter the desired password length: "))
password = generate_password(length)
if password:
print(f"Generated password: {password}")
except ValueError:
print("Please enter a valid number!")
if __name__ == "__main__":
main()