-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
52 lines (33 loc) · 1.18 KB
/
server.js
File metadata and controls
52 lines (33 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const express = require('express')
const app = express()
app.get('/', (req, res) => {
// TODO: Authentifizierung mit Basic Auth bauen
// Pseudo
// Authorization Header aus dem req-Objekt abfragen
// Prüfen ob Authorization Header gegeben
// wenn nicht, Fehler
// wenn ja, prüfen ob Nutzername und Passwort stimmen
var auth = null;
if (!auth) {
// Popup für Abfrage nach Nutzername und Passwort
res.setHeader('WWW-Authenticate', 'Basic realm="Secure Area"');
// Fehlermeldung
} else {
// Ausgabe des Authorization Header in Plaintext
var plain_auth = new Buffer(auth.split(' ')[1], 'base64').toString().split(':');
console.log("Authorization ", plain_auth);
// Nutzername und Passwort aus plain_auth extrahieren (Tipp: Array)
var username = null;
var password = null;
// Wenn Nutzername == "Selbst definierter Nutzername" und Passwort == "Selbst definiertes Passwort"
if (true) {
// Erfolgsmeldung
} else {
res.setHeader('WWW-Authenticate', 'Basic realm="Secure Area"');
// sonst Fehlermeldung
}
}
});
app.listen(3000, function() {
console.log("Server ist listening on http://localhost:3000/");
});