Skip to content

Commit 50bf585

Browse files
committed
added simple test for sanity check
1 parent 08ebdee commit 50bf585

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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

Comments
 (0)