Added ip logging for failed login attempts
This commit is contained in:
parent
f62b580d46
commit
fa9ca9613d
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,4 +2,5 @@
|
|||||||
*index-*.html
|
*index-*.html
|
||||||
/node_modules/
|
/node_modules/
|
||||||
*.pem
|
*.pem
|
||||||
|
/failed-login-attempts.txt
|
||||||
|
|
||||||
|
14
server.js
14
server.js
@ -158,10 +158,19 @@ function testAuthentication(request, response) {
|
|||||||
response.end('Access granted! You\'re in!');
|
response.end('Access granted! You\'re in!');
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
|
// Log failed login attempt
|
||||||
|
console.log('Failed login attempt by ' + request.connection.remoteAddress);
|
||||||
|
const now = new Date();
|
||||||
|
fs.appendFile(
|
||||||
|
'failed-login-attempts.txt',
|
||||||
|
'[' + (now.getDate()+1) + '.' + (now.getMonth()+1) + '.' + now.getFullYear() + ' ' + now.getHours() + ':' + now.getMinutes() + ':' + now.getSeconds() + '] Failed login attempt by ' + request.connection.remoteAddress + '\n',
|
||||||
|
() => {}
|
||||||
|
);
|
||||||
|
|
||||||
response.writeHead(401, {
|
response.writeHead(401, {
|
||||||
'Content-Type': 'text/html'
|
'Content-Type': 'text/html'
|
||||||
});
|
});
|
||||||
response.end('WOOP! WOOP! Invalid password!<br><br>Need to reset your password? Replace the password hash in config.yaml with a new one.<br>This password hashes to: <em>' + passwordHash + '</em>.');
|
response.end('WOOP! WOOP! Invalid password!<br>This attempt as been logged.<br><br>Need to reset your password? Replace the password hash in config.yaml with a new one.<br>This password hashes to: <em>' + passwordHash + '</em>.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -209,9 +218,6 @@ const serverOptions = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var server = https.createServer(serverOptions, function (request, response) {
|
var server = https.createServer(serverOptions, function (request, response) {
|
||||||
// Handle requests here...
|
|
||||||
console.log(request.headers.referer);
|
|
||||||
|
|
||||||
// If request is trying to authenticate
|
// If request is trying to authenticate
|
||||||
if (request.url == '/api--authenticate') {
|
if (request.url == '/api--authenticate') {
|
||||||
testAuthentication(request, response);
|
testAuthentication(request, response);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user