import random
import string
def generate_password(length=8, use_uppercase=True, use_digits=True, use_special_chars=True):
characters = string.ascii_lowercase
if use_uppercase:
characters += string.ascii_uppercase
if use_digits:
characters += string.digits
if use_special_chars:
characters += string.punctuation
if length < 1:
raise ValueError("Password length must be at least 1")
password = ''.join(random.choice(characters) for _ in range(length))
return password
def match_password(entered_password, reference_password):
return entered_password == reference_password
# Example usage
reference_password = generate_password(length=12, use_uppercase=True, use_digits=True, use_special_chars=True)
print("Reference Password:", reference_password)
entered_password = input("Enter your password: ")
if match_password(entered_password, reference_password):
print("Password matched!")
else:
print("Password didn't match.")