61 lines
1.9 KiB
Python
61 lines
1.9 KiB
Python
"""
|
|
Test script to demonstrate password hashing and verification
|
|
"""
|
|
|
|
from werkzeug.security import generate_password_hash, check_password_hash
|
|
|
|
# Example: Creating a hashed password
|
|
plain_password = "mySecurePassword123"
|
|
hashed_password = generate_password_hash(plain_password, method='pbkdf2:sha256')
|
|
|
|
print("=" * 60)
|
|
print("PASSWORD HASHING DEMONSTRATION")
|
|
print("=" * 60)
|
|
print()
|
|
print(f"Original Password: {plain_password}")
|
|
print()
|
|
print(f"Hashed Password: {hashed_password}")
|
|
print()
|
|
print(f"Hash Length: {len(hashed_password)} characters")
|
|
print()
|
|
print("=" * 60)
|
|
print("SECURITY FEATURES")
|
|
print("=" * 60)
|
|
print("✓ Algorithm: PBKDF2-SHA256")
|
|
print("✓ Iterations: 600,000+")
|
|
print("✓ Unique salt per password")
|
|
print("✓ Cannot be reversed to plain text")
|
|
print("✓ Industry-standard security")
|
|
print()
|
|
print("=" * 60)
|
|
print("PASSWORD VERIFICATION TEST")
|
|
print("=" * 60)
|
|
print()
|
|
|
|
# Test correct password
|
|
correct = check_password_hash(hashed_password, "mySecurePassword123")
|
|
print(f"Testing correct password: {correct} ✓")
|
|
|
|
# Test incorrect password
|
|
incorrect = check_password_hash(hashed_password, "wrongPassword")
|
|
print(f"Testing incorrect password: {incorrect} ✗")
|
|
print()
|
|
|
|
# Show that the same password produces different hashes (due to unique salts)
|
|
print("=" * 60)
|
|
print("UNIQUE SALT DEMONSTRATION")
|
|
print("=" * 60)
|
|
print()
|
|
print("Hashing the same password twice produces different hashes:")
|
|
print()
|
|
hash1 = generate_password_hash("password123", method='pbkdf2:sha256')
|
|
hash2 = generate_password_hash("password123", method='pbkdf2:sha256')
|
|
print(f"Hash 1: {hash1}")
|
|
print(f"Hash 2: {hash2}")
|
|
print()
|
|
print(f"Are they different? {hash1 != hash2}")
|
|
print("Both hashes are valid and will verify correctly!")
|
|
print(f"Hash 1 verifies: {check_password_hash(hash1, 'password123')}")
|
|
print(f"Hash 2 verifies: {check_password_hash(hash2, 'password123')}")
|
|
print()
|