Bruteforce Mitigation

This commit is contained in:
Tina_Azure
2023-05-08 14:52:36 +02:00
parent 8d2033b316
commit 6ee74e025e
10 changed files with 259 additions and 58 deletions

View File

@ -222,7 +222,6 @@ namespace Database {
/*
* Executes the PURGE_EXPIRED_FREELANCER_RESET_KEYS statement
* Takes an open pqxx::connection
* todo::regular execution
*/
void executeStatement_STATEMENT_PURGE_EXPIRED_FREELANCER_RESET_KEYS(pqxx::connection &connection) {
pqxx::work work(connection);
@ -230,6 +229,16 @@ namespace Database {
work.commit();
}
/*
* Executes the PURGE_EXPIRED_LOGIN_LOCKOUTS statement
* Takes an open pqxx::connection
*/
void executeStatement_STATEMENT_PURGE_EXPIRED_LOGIN_LOCKOUTS(pqxx::connection &connection) {
pqxx::work work(connection);
work.exec(SQL_STATEMENT_PURGE_EXPIRED_LOGIN_LOCKOUTS);
work.commit();
}
/*
* Executes the prepared statement SELECT_ITEM_BY_ID
* Takes an open pqxx::connection and the id to select by
@ -332,6 +341,73 @@ namespace Database {
return result;
}
/*
* Executes the prepared statement SELECT_CHECK_LOGIN_LOCK_OUT
* Takes an open pqxx::connection and the emailAddress
* Delivers true if the login for the given email is locked
*/
pqxx::result executePreparedStatement_SELECT_CHECK_LOGIN_LOCK_OUT(pqxx::connection &connection, const std::string& emailAddress) {
pqxx::work work(connection);
pqxx::result result = work.exec_prepared(PREPARED_STATEMENT_SELECT_CHECK_LOGIN_LOCK_OUT, emailAddress);
work.commit();
return result;
}
/*
* Executes the prepared statement SELECT_GET_LOGIN_LOCK_OUT_MINUTES
* Takes an open pqxx::connection and the emailAddress
* Delivers minutes until the login lock out expires
*/
pqxx::result executePreparedStatement_SELECT_GET_LOGIN_LOCK_OUT_MINUTES(pqxx::connection &connection, const std::string& emailAddress) {
pqxx::work work(connection);
pqxx::result result = work.exec_prepared(PREPARED_STATEMENT_SELECT_GET_LOGIN_LOCK_OUT_MINUTES, emailAddress);
work.commit();
return result;
}
/*
* Executes the prepared statement INSERT_LOGIN_LOCK_OUT
* Takes an open pqxx::connection and the emailAddress
*/
void executePreparedStatement_INSERT_LOGIN_LOCK_OUT(pqxx::connection &connection, const std::string& emailAddress) {
pqxx::work work(connection);
pqxx::result result = work.exec_prepared(PREPARED_STATEMENT_INSERT_LOGIN_LOCK_OUT, emailAddress);
work.commit();
}
/*
* Executes the prepared statement UPDATE_INCREMENT_LOGIN_LOCK_OUT_ATTEMPTS
* Takes an open pqxx::connection and the emailAddress
*/
void executePreparedStatement_UPDATE_INCREMENT_LOGIN_LOCK_OUT_ATTEMPTS(pqxx::connection &connection, const std::string& emailAddress) {
pqxx::work work(connection);
pqxx::result result = work.exec_prepared(PREPARED_STATEMENT_UPDATE_INCREMENT_LOGIN_LOCK_OUT_ATTEMPTS, emailAddress);
work.commit();
}
/*
* Executes the prepared statement CHECK_LOGIN_LOCK_OUT_ATTEMPTS
* Takes an open pqxx::connection the emailAddress and the max attempts
* returns true if the lock out attempts, exceed or equate the given max attempts
*/
pqxx::result executePreparedStatement_CHECK_LOGIN_LOCK_OUT_ATTEMPTS(pqxx::connection &connection, const std::string& emailAddress, int maxAttempts) {
pqxx::work work(connection);
pqxx::result result = work.exec_prepared(PREPARED_STATEMENT_SELECT_CHECK_LOGIN_LOCK_OUT_ATTEMPTS, emailAddress, maxAttempts);
work.commit();
return result;
}
/*
* Executes the prepared statement UPDATE_EXPIRATION_LOGIN_LOCK_OUT
* Takes an open pqxx::connection the emailAddress and the additive lock out in seconds
*/
void executePreparedStatement_UPDATE_EXPIRATION_LOGIN_LOCK_OUT(pqxx::connection &connection, const std::string& emailAddress, int lockOutSeconds) {
pqxx::work work(connection);
std::string lockOutString = std::to_string(lockOutSeconds) + " second";
pqxx::result result = work.exec_prepared(PREPARED_STATEMENT_UPDATE_EXPIRATION_LOGIN_LOCK_OUT, emailAddress, lockOutSeconds);
work.commit();
}
/*
* Executes the prepared statement SELECT_TEMPLATE
* Takes an open pqxx::connection and the id to select by