python code train password similar
- User
python code
train password similar
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
python code
train password similar
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Here's a Python script that can help check if a password is too similar to common patterns or previous passwords:
import difflib
from collections import defaultdict
class PasswordSimilarityChecker:
def __init__(self):
# Common password patterns to check against
self.common_patterns = [
'password', '123456', 'qwerty', 'admin', 'welcome',
'letmein', 'monkey', 'sunshine', 'iloveyou', 'football'
]
# User's previous passwords (would be populated from a database in real use)
self.previous_passwords = []
# Similarity threshold (0-1), higher means more strict
self.similarity_threshold = 0.7
def add_previous_password(self, password):
"""Add a password to the history of previous passwords"""
self.previous_passwords.append(password)
def is_too_similar(self, new_password):
"""
Check if a new password is too similar to common patterns or previous passwords
Returns True if too similar, False if acceptable
"""
# Check against common patterns
for pattern in self.common_patterns:
similarity = difflib.SequenceMatcher(None, new_password.lower(), pattern).ratio()
if similarity >= self.similarity_threshold:
return True
# Check against previous passwords
for old_password in self.previous_passwords:
similarity = difflib.SequenceMatcher(None, new_password.lower(), old_password.lower()).ratio()
if similarity >= self.similarity_threshold:
return True
return False
def suggest_stronger_password(self, weak_password):
"""Suggest a stronger version of a weak password"""
# This is a simple example - in practice you'd use a more sophisticated method
if weak_password.isalpha():
return weak_password + '123!'
elif weak_password.isdigit():
return '!' + weak_password + 'Ab'
else:
return weak_password.capitalize() + '42!'
# Example usage
if __name__ == "__main__":
checker = PasswordSimilarityChecker()
# Add some previous passwords
checker.add_previous_password("Summer2022")
checker.add_previous_password("P@ssw0rd")
# Test some passwords
test_passwords = [
"summer2023", # Similar to previous
"Password123", # Similar to common pattern
"123456789", # Common pattern
"MySecureP@ss!2023", # Strong password
"winter2021" # Not similar
]
for pwd in test_passwords:
if checker.is_too_similar(pwd):
print(f"'{pwd}' is too similar to previous passwords or common patterns.")
suggestion = checker.suggest_stronger_password(pwd)
print(f"Consider using something like: {suggestion}")
else:
print(f"'{pwd}' is acceptable.")
PasswordSimilarityCheckeradd_previous_password()is_too_similar()suggest_stronger_password()In a real application, you would: