#!/usr/bin/env node /** * Verify enhanced authentication is active and working */ const { db } = require('../src/database/db'); console.log('=== Verifying Enhanced Authentication Activation ===\n'); async function verifyAuth() { const results = { databaseTables: false, serverConfig: false, lockoutActive: false, cleanupActive: false }; try { // 1. Check database tables console.log('1. Checking database tables...'); const hasLoginAttempts = await db.schema.hasTable('login_attempts'); const hasSecurityColumns = await db.schema.hasColumn('admin_users', 'password_changed_at'); if (hasLoginAttempts && hasSecurityColumns) { results.databaseTables = true; console.log('✓ Auth tables and columns exist'); // Count attempts const attempts = await db('login_attempts').count().first(); console.log(` Total login attempts tracked: ${attempts['count(*)'] || 0}`); } else { console.log('✗ Auth tables missing'); } // 2. Check server configuration console.log('\n2. Checking server configuration...'); const fs = require('fs'); const serverContent = fs.readFileSync('./server.js', 'utf8'); if (serverContent.includes("require('./src/routes/auth-enhanced')")) { results.serverConfig = true; console.log('✓ Server using enhanced auth routes'); } else { console.log('✗ Server using original auth routes'); } if (serverContent.includes('initializeCleanupJob')) { results.cleanupActive = true; console.log('✓ Cleanup job initialized'); } else { console.log('✗ Cleanup job not initialized'); } // 3. Test lockout functionality console.log('\n3. Testing lockout functionality...'); const { checkAccountLockout } = require('../src/utils/authSecurity'); // Check a test account const lockoutTest = await checkAccountLockout('lockout-test-user'); console.log(`✓ Lockout check functional: ${lockoutTest.isLocked ? 'locked' : 'not locked'}`); results.lockoutActive = true; // 4. Check recent activity console.log('\n4. Recent authentication activity...'); const recentAttempts = await db('login_attempts') .orderBy('attempt_time', 'desc') .limit(5); if (recentAttempts.length > 0) { console.log('Recent login attempts:'); recentAttempts.forEach(attempt => { const time = new Date(attempt.attempt_time).toLocaleString(); console.log(` ${time} - ${attempt.identifier} - ${attempt.success ? 'SUCCESS' : 'FAILED'}`); }); } else { console.log('No login attempts recorded yet'); } // Summary console.log('\n=== Summary ==='); const allGood = Object.values(results).every(v => v === true); if (allGood) { console.log('✅ Enhanced authentication is FULLY ACTIVE!'); console.log('\nFeatures enabled:'); console.log('- Account lockout protection (5 attempts)'); console.log('- Login attempt tracking'); console.log('- Enhanced token validation'); console.log('- Session management'); console.log('- Automatic cleanup of old records'); } else { console.log('⚠️ Some features not active:'); Object.entries(results).forEach(([key, value]) => { console.log(` ${key}: ${value ? '✓' : '✗'}`); }); } } catch (error) { console.error('Verification error:', error); } finally { await db.destroy(); } } verifyAuth();