Finished adding JSDoc for src/utils
This commit is contained in:
parent
2303c89bcf
commit
7b8c44158f
12 changed files with 229 additions and 20 deletions
|
|
@ -19,15 +19,33 @@ const config = require('../../config.json');
|
|||
const {userModel} = require('../schemas/user/userSchema.js');
|
||||
const userBanModel = require('../schemas/user/userBanSchema.js')
|
||||
const altchaUtils = require('../utils/altchaUtils.js');
|
||||
const loggerUtils = require('../utils/loggerUtils.js')
|
||||
const loggerUtils = require('../utils/loggerUtils.js');
|
||||
|
||||
//Create failed sign-in cache since it's easier and more preformant to implement it this way than adding extra burdon to the database
|
||||
//Server restarts are far and few between. It would take multiple during a single bruteforce attempt for this to become an issue.
|
||||
/**
|
||||
* Create failed sign-in cache since it's easier and more preformant to implement it this way than adding extra burdon to the database
|
||||
* Server restarts are far and few between. It would take multiple during a single bruteforce attempt for this to become an issue.
|
||||
*/
|
||||
const failedAttempts = new Map();
|
||||
|
||||
/**
|
||||
* How many failed attempts required to throttle with altcha
|
||||
*/
|
||||
const throttleAttempts = 5;
|
||||
|
||||
/**
|
||||
* How many attempts to lock user account out for the day
|
||||
*/
|
||||
const maxAttempts = 200;
|
||||
|
||||
//this module is good for keeping wrappers for userModel and other shit in that does more session handling than database access/modification.
|
||||
/**
|
||||
* Sole and Singular Session Authentication method.
|
||||
* All logins should happen through here, all other site-wide authentication should happen by sessions authenticated by this model.
|
||||
* This is important, as reducing authentication endpoints reduces attack surface.
|
||||
* @param {String} user - Username to login as
|
||||
* @param {String} pass - Password to authenticat session with
|
||||
* @param {express.Request} req - Express request object w/ session to authenticate
|
||||
* @returns Username of authticated user upon success
|
||||
*/
|
||||
module.exports.authenticateSession = async function(user, pass, req){
|
||||
//Fuck you yoda
|
||||
try{
|
||||
|
|
@ -137,15 +155,27 @@ module.exports.authenticateSession = async function(user, pass, req){
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs user out and destroys all server-side traces of a given session
|
||||
* @param {express-session.session} session
|
||||
*/
|
||||
module.exports.killSession = async function(session){
|
||||
session.destroy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns how many failed login attempts within the past day or so since the last login has occured for a given user
|
||||
* @param {String} user - User to check map against
|
||||
* @returns {Number} of failed login attempts
|
||||
*/
|
||||
module.exports.getLoginAttempts = function(user){
|
||||
//Read the code, i'm not explaining this
|
||||
return failedAttempts.get(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Nightly Function Call which iterates through the failed login attempts map, removing any which haven't been attempted in over a da yeahy
|
||||
*/
|
||||
module.exports.processExpiredAttempts = function(){
|
||||
for(user of failedAttempts.keys()){
|
||||
//Get attempt by user
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue