Clean up code structure

This commit is contained in:
2025-10-09 11:25:03 +02:00
parent 67e81fee90
commit 327bdb17b4
5 changed files with 356 additions and 149 deletions
+5 -13
View File
@@ -5,21 +5,15 @@ const app = express();
const port = 3000;
const axios = require('axios');
const HCAPTCHA_SECRET = '0x0000000000000000000000000000000000000000';
app.use(express.json());
const LOG_FILE = path.join(__dirname, 'login.log');
const users = JSON.parse(fs.readFileSync('C:/Users/frederik/WebstormProjects/BruteForce/TEST_DATA/users.json', 'utf8'));
// Konfiguration
const LINEAR_DELAY_MS = 1000; // 1s
const PROGRESSIVE_DELAYS = [10000, 60000, 300000]; // 10s, 1min, 5min
const users = JSON.parse(fs.readFileSync('TEST_DATA/users.json', 'utf8'));
const LINEAR_DELAY_MS = 1000;
const PROGRESSIVE_DELAYS = [10000, 60000, 300000];
const LOCKOUT_THRESHOLD = 5;
const LOCKOUT_DURATION = 15 * 60 * 1000; // 15 Minuten
const LOCKOUT_DURATION = 15 * 60 * 1000;
const loginAttempts = {};
const loginAttempts = {}; // { username: { count, lockedUntil, lastFail, requiresCaptcha } }
// Logging-Funktion
function logAttempt(username, status, ip, extra = '') {
const timestamp = new Date().toISOString();
const logLine = `[${timestamp}] [${ip}] [${username}] [${status}] ${extra}\n`;
@@ -30,10 +24,8 @@ function logAttempt(username, status, ip, extra = '') {
app.post('/login', async (req, res) => {
const { username, password, captcha } = req.body;
const ip = req.ip || req.connection.remoteAddress;
const user = users.find(u => u.username === username && u.password === password);
const now = Date.now();
// Init
if (!loginAttempts[username]) {
loginAttempts[username] = {
+21
View File
@@ -0,0 +1,21 @@
[
{
"username": "test",
"password": "test"
},
{
"username": "caps",
"password": "QWERTYUIOP"
},
{
"username": "numbers",
"password": "4938271056"
},
{
"username": "lower",
"password": "abcdefghij"
}
]
+1
View File
@@ -134,6 +134,7 @@
} else {
msg.textContent = '❌ ' + (data.error || 'Login fehlgeschlagen');
msg.className = 'msg error';
msg.style.display = 'block';
if (data.requiresCaptcha) {
captchaContainer.style.display = 'block';
hcaptcha.reset();