Spaces:
Sleeping
Sleeping
import random | |
import string | |
def generate_password(): | |
# Define characters, numbers, and special characters | |
chars = string.ascii_lowercase + string.ascii_uppercase + string.digits + "@#&" | |
# Ensure at least one character from each category | |
password = random.choice(string.ascii_lowercase) \ | |
+ random.choice(string.ascii_uppercase) \ | |
+ random.choice(string.digits) \ | |
+ random.choice("@#&") | |
# Add remaining characters randomly | |
password += ''.join(random.choice(chars) for _ in range(4)) | |
# Shuffle the password to mix characters | |
password_list = list(password) | |
random.shuffle(password_list) | |
password = ''.join(password_list) | |
return password |