Sri Lanka takes control of an Iranian vessel off its coast after U.S. sank an Iranian warship

Chronological Source Flow
Back

AI Fusion Summary

Here's a simple Python program that generates a random password with a mix of uppercase letters, lowercase letters, digits, and special characters. The password will be 12 characters long by default, but you can adjust the length if you want. ```python import random import string def generate_password(length=12): # Define the character sets uppercase_letters = string.ascii_uppercase lowercase_letters = string.ascii_lowercase digits = string.digits special_chars = string.punctuation # Ensure the password has at least one of each character type password = [ random.choice(uppercase_letters), random.choice(lowercase_letters), random.choice(digits), random.choice(special_chars) ] # Fill the rest of the password length with a mix of all character types all_chars = uppercase_letters + lowercase_letters + digits + special_chars for i in range(length - 4): password.append(random.choice(all_chars)) # Shuffle the password to avoid predictable patterns random.shuffle(password) # Convert the list to a string and return it return ''.join(password) # Generate and print a password if __name__ == "__main__": password = generate_password() print("Generated Password:", password) ``` This code ensures that the password includes at least one uppercase letter, one lowercase letter, one digit, and one special character. The rest of the password is filled with a random selection from all character sets, and then the password is shuffled to avoid having the required characters at the beginning or in a predictable pattern. You can change the default length by passing a different value to the `generate_password` function, e.g., `generate_password(16)` for a 16-character password.
3 Πηγές
06/03 14:10 twincities.com
Comments
Loading...
0