|
| 1 | +import { hashPassword, comparePassword } from './password_hash'; |
| 2 | + |
| 3 | +async function testPasswordHashing() { |
| 4 | + console.log('🧪 Testing Password Hashing...\n'); |
| 5 | + |
| 6 | + // Test 1: Hash a password |
| 7 | + const plainPassword = 'mySecretPassword123'; |
| 8 | + console.log('Original password:', plainPassword); |
| 9 | + |
| 10 | + const hashedPassword = await hashPassword(plainPassword); |
| 11 | + console.log('Hashed password:', hashedPassword); |
| 12 | + console.log('Hash length:', hashedPassword.length, 'characters\n'); |
| 13 | + |
| 14 | + // Test 2: Verify correct password |
| 15 | + const isCorrect = await comparePassword(plainPassword, hashedPassword); |
| 16 | + console.log('Testing correct password:', isCorrect ? 'PASS' : 'FAIL'); |
| 17 | + |
| 18 | + // Test 3: Verify wrong password |
| 19 | + const isWrong = await comparePassword('wrongPassword', hashedPassword); |
| 20 | + console.log('Testing wrong password:', !isWrong ? 'PASS' : 'FAIL'); |
| 21 | + |
| 22 | + // Test 4: Same password hashes differently each time (salt!) |
| 23 | + const hash1 = await hashPassword(plainPassword); |
| 24 | + const hash2 = await hashPassword(plainPassword); |
| 25 | + console.log('\nSame password, different hashes (proves salt works):'); |
| 26 | + console.log('Hash 1:', hash1); |
| 27 | + console.log('Hash 2:', hash2); |
| 28 | + console.log('Are they different?', hash1 !== hash2 ? 'YES' : 'NO'); |
| 29 | +} |
| 30 | + |
| 31 | +testPasswordHashing(); |
0 commit comments