Merge pull request #31 from Newtbot/BRUTEFORCE
ADDED BRUTE FORCE PREVENTION
This commit is contained in:
commit
a6ae83265e
@ -1,5 +1,6 @@
|
|||||||
const express = require("express");
|
const express = require("express");
|
||||||
const session = require("express-session");
|
const session = require("express-session");
|
||||||
|
const rateLimit = require('express-rate-limit');
|
||||||
const mysql2 = require('mysql2');
|
const mysql2 = require('mysql2');
|
||||||
const bodyParser = require("body-parser");
|
const bodyParser = require("body-parser");
|
||||||
const bcrypt = require("bcrypt");
|
const bcrypt = require("bcrypt");
|
||||||
@ -128,6 +129,14 @@ const logActivity = async (username, success, message) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
const limiter = rateLimit({
|
||||||
|
windowMs: 15 * 60 * 1000, // 15 minutes
|
||||||
|
max: 5, // limit each IP to 3 requests per windowMs
|
||||||
|
message: 'Too many login attempts from this IP, please try again later.',
|
||||||
|
});
|
||||||
|
app.use('/login', limiter);
|
||||||
|
|
||||||
app.post('/login', [
|
app.post('/login', [
|
||||||
body('username').escape().trim().isLength({ min: 1 }).withMessage('Username must not be empty'),
|
body('username').escape().trim().isLength({ min: 1 }).withMessage('Username must not be empty'),
|
||||||
body('password').escape().trim().isLength({ min: 1 }).withMessage('Password must not be empty'),
|
body('password').escape().trim().isLength({ min: 1 }).withMessage('Password must not be empty'),
|
||||||
|
2685
package-lock.json
generated
2685
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user