-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtestPassword.js
More file actions
65 lines (54 loc) · 2.58 KB
/
Copy pathtestPassword.js
File metadata and controls
65 lines (54 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
const mongoose = require('mongoose');
const bcrypt = require('bcrypt');
const MONGO_URI = 'mongodb+srv://root:passpro@cluster-1.9u8zstf.mongodb.net/test';
const testPassword = async () => {
try {
console.log('🔍 Connecting to test database...');
await mongoose.connect(MONGO_URI);
console.log('✅ Connected to test database');
// Get the Users collection
const users = mongoose.connection.db.collection('Users');
// Find the super admin
const superAdmin = await users.findOne({ email: 'natnaeldarsema@gmail.com' });
if (!superAdmin) {
console.log('❌ Super admin not found!');
return;
}
console.log('✅ Super admin found!');
console.log('📋 User details:');
console.log(' - Name:', superAdmin.name);
console.log(' - Email:', superAdmin.email);
console.log(' - Role:', superAdmin.role);
console.log(' - Is Verified:', superAdmin.isVerified);
console.log(' - Has Password:', !!superAdmin.password);
console.log(' - Password Hash:', superAdmin.password ? superAdmin.password.substring(0, 30) + '...' : 'MISSING');
if (superAdmin.password) {
console.log('\n🔐 Testing password comparison...');
const testPassword = 'SuperAdmin123!';
const isMatch = await bcrypt.compare(testPassword, superAdmin.password);
console.log(' - Test Password:', testPassword);
console.log(' - Password Match:', isMatch ? '✅ CORRECT' : '❌ INCORRECT');
if (!isMatch) {
console.log('\n🔧 Trying to hash the password manually...');
const saltRounds = 12;
const hashedPassword = await bcrypt.hash(testPassword, saltRounds);
console.log(' - Manual Hash:', hashedPassword.substring(0, 30) + '...');
console.log(' - Stored Hash:', superAdmin.password.substring(0, 30) + '...');
console.log(' - Hashes Match:', hashedPassword === superAdmin.password ? '✅ YES' : '❌ NO');
// Try different salt rounds
console.log('\n🔧 Testing different salt rounds...');
for (let rounds = 10; rounds <= 12; rounds++) {
const testHash = await bcrypt.hash(testPassword, rounds);
const testMatch = await bcrypt.compare(testPassword, testHash);
console.log(` - Salt rounds ${rounds}: ${testMatch ? '✅ Works' : '❌ Fails'}`);
}
}
}
} catch (error) {
console.error('❌ Error:', error.message);
} finally {
await mongoose.disconnect();
console.log('\n🔌 Disconnected from MongoDB');
}
};
testPassword();