handlerlogin: use std::atomic for counter and lockguard in ban check
This commit is contained in:
bovenliggende
d02e8d0dce
commit
232ff75ae0
@ -18,12 +18,15 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#include <atomic>
|
||||
#include <mutex>
|
||||
#include <openssl/evp.h>
|
||||
#include "handlerlogin.h"
|
||||
#include "../logger.h"
|
||||
struct LoginFail
|
||||
{
|
||||
unsigned int count;
|
||||
std::mutex mutex;
|
||||
std::atomic<unsigned int> count;
|
||||
time_t lastfail;
|
||||
};
|
||||
static std::map<std::string, LoginFail> loginFails;
|
||||
@ -34,6 +37,7 @@ bool HandlerLogin::isBanned(std::string ip)
|
||||
if(utils::hasKey(loginFails, ip))
|
||||
{
|
||||
LoginFail &fl = loginFails[ip];
|
||||
std::lock_guard<std::mutex> lock(fl.mutex);
|
||||
return fl.count > 5 && (time(nullptr) - fl.lastfail) < 1200;
|
||||
|
||||
}
|
||||
|
Laden…
Verwijs in nieuw issue
Block a user