File size: 743 Bytes
f31a243
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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