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
+1
View File
@@ -0,0 +1 @@
[]
View File
+31
View File
@@ -0,0 +1,31 @@
{
"name": "bruteforce",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Fretuks/BruteForce.git"
},
"private": true,
"dependencies": {
"bcryptjs": "^3.0.2",
"body-parser": "^2.2.0",
"cors": "^2.8.5",
"express": "^5.1.0"
},
"directories": {
"doc": "docs"
},
"keywords": [],
"author": "",
"license": "ISC",
"type": "commonjs",
"bugs": {
"url": "https://github.com/Fretuks/BruteForce/issues"
},
"homepage": "https://github.com/Fretuks/BruteForce#readme"
}
+6 -2
View File
@@ -1,11 +1,11 @@
const express = require('express'); const express = require('express');
const fs = require('fs'); const fs = require('fs');
const app = express(); const app = express();
const port = 3000; const port = 3000;
app.use(express.json()); 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) => { app.post('/login', (req, res) => {
const {username, password} = req.body; const {username, password} = req.body;
const user = users.find(u => u.username === username && u.password === password); const user = users.find(u => u.username === username && u.password === password);
@@ -17,6 +17,10 @@ app.post('/login', (req, res) => {
} }
}); });
app.get('/login', (req, res) => {
res.sendFile(__dirname + '/index.html');
});
app.listen(port, () => { 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> <head>
<meta charset="UTF-8"> <meta charset="utf-8" />
<title>BruteForce</title> <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> </head>
<body> <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> </body>
</html> </html>
View File