59 lines
1.5 KiB
TypeScript
59 lines
1.5 KiB
TypeScript
// Test admin password verification
|
|
import * as dotenv from 'dotenv';
|
|
import path from 'node:path';
|
|
import fs from 'node:fs';
|
|
|
|
const envPaths = [
|
|
path.resolve(process.cwd(), '.env.local'),
|
|
path.resolve(process.cwd(), '.env'),
|
|
path.resolve(__dirname, '..', '.env.local'),
|
|
path.resolve(__dirname, '..', '.env'),
|
|
];
|
|
|
|
for (const envPath of envPaths) {
|
|
if (fs.existsSync(envPath)) {
|
|
dotenv.config({ path: envPath });
|
|
break;
|
|
}
|
|
}
|
|
|
|
import { PrismaClient } from '@prisma/client';
|
|
import { compare } from 'bcryptjs';
|
|
|
|
const prisma = new PrismaClient();
|
|
|
|
async function testPassword() {
|
|
const username = 'admin';
|
|
const testPassword = process.env.ADMIN_PASSWORD || '*MrV0D0cy#';
|
|
|
|
try {
|
|
const admin = await prisma.admin.findUnique({
|
|
where: { username },
|
|
});
|
|
|
|
if (!admin) {
|
|
console.error('❌ Admin user not found!');
|
|
return;
|
|
}
|
|
|
|
console.log(`✅ Admin user found: ${username}`);
|
|
console.log(`📝 Testing password: ${testPassword}`);
|
|
console.log(`🔐 Stored hash: ${admin.password.substring(0, 20)}...`);
|
|
|
|
const isValid = await compare(testPassword, admin.password);
|
|
|
|
if (isValid) {
|
|
console.log('✅ Password verification: SUCCESS');
|
|
} else {
|
|
console.log('❌ Password verification: FAILED');
|
|
console.log('\n💡 Try running: npm run admin:reset-password');
|
|
}
|
|
} catch (error) {
|
|
console.error('❌ Error:', error);
|
|
} finally {
|
|
await prisma.$disconnect();
|
|
}
|
|
}
|
|
|
|
testPassword();
|