Add authentication flow, client UI, and dependencies

This commit is contained in:
2025-09-24 10:07:49 +02:00
parent 21c35d7e41
commit 3217ed5871
7 changed files with 95 additions and 14 deletions
+14 -10
View File
@@ -1,22 +1,26 @@
const express = require('express');
const express = require('express');
const fs = require('fs');
const app = express();
const port = 3000;
app.use(express.json());
const users = JSON.parse(fs.readFileSync('users.json', 'utf8'));
const users = JSON.parse(fs.readFileSync('C:/Users/frederik/WebstormProjects/BruteForce/TEST_DATA/users.json', 'utf8'));
app.post('/login', (req, res) => {
const { username, password } = req.body;
const user = users.find(u => u.username === username && u.password === password);
const {username, password} = req.body;
const user = users.find(u => u.username === username && u.password === password);
if (user) {
res.send('Login erfolgreich');
} else {
res.status(401).send('Falscher Benutzername oder Passwort');
}
if (user) {
res.send('Login erfolgreich');
} else {
res.status(401).send('Falscher Benutzername oder Passwort');
}
});
app.get('/login', (req, res) => {
res.sendFile(__dirname + '/index.html');
});
app.listen(port, () => {
console.log(`läuft http://localhost:${port}`);
console.log(`läuft http://localhost:${port}`);
});
View File
+49 -4
View File
@@ -1,10 +1,55 @@
<!DOCTYPE html>
<html lang="en">
<!doctype html>
<html lang="de">
<head>
<meta charset="UTF-8">
<title>BruteForce</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<title>Login Demo</title>
<style>
body{font-family:system-ui,Segoe UI,Roboto,Arial;margin:32px}
form{max-width:360px}
input{display:block;margin:8px 0;padding:8px;width:100%}
button{padding:8px 12px}
.msg{margin-top:12px}
</style>
</head>
<body>
<h1>Login (Demo)</h1>
<form id="login">
<label>Benutzername
<input id="username" name="username" autocomplete="username" required />
</label>
<label>Passwort
<input id="password" name="password" type="password" autocomplete="current-password" required />
</label>
<button type="submit">Login</button>
</form>
<div class="msg" id="msg"></div>
<script>
const form = document.getElementById('login');
const msg = document.getElementById('msg');
form.addEventListener('submit', async (e) => {
e.preventDefault();
msg.textContent = 'Sende...';
const username = document.getElementById('username').value;
const password = document.getElementById('password').value;
try {
const res = await fetch('/login', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ username, password })
});
const data = await res.json();
if (res.ok && data.ok) {
msg.textContent = 'Erfolgreich authentifiziert!';
} else {
msg.textContent = 'Fehler: ' + (data.error || res.statusText);
}
} catch (err) {
msg.textContent = 'Netzwerkfehler';
}
});
</script>
</body>
</html>
View File