Automatically clean failed login attempts

This commit is contained in:
2022-04-03 16:45:25 +02:00
parent 05e911bfc5
commit 9943df4952
3 changed files with 26 additions and 6 deletions

View File

@@ -1,7 +1,9 @@
use std::collections::HashMap;
use std::net::IpAddr;
use crate::constants::KEEP_FAILED_LOGIN_ATTEMPTS_FOR;
use actix::{Actor, AsyncContext, Context};
use crate::constants::{FAIL_LOGIN_ATTEMPT_CLEANUP_INTERVAL, KEEP_FAILED_LOGIN_ATTEMPTS_FOR};
use crate::utils::time::time;
#[derive(Debug, Default)]
@@ -41,6 +43,18 @@ impl BruteForceActor {
}
}
impl Actor for BruteForceActor {
type Context = Context<Self>;
fn started(&mut self, ctx: &mut Self::Context) {
// Clean up at a regular interval failed attempts
ctx.run_interval(FAIL_LOGIN_ATTEMPT_CLEANUP_INTERVAL, |act, _ctx| {
log::trace!("Cleaning up failed login attempts");
act.clean_attempts();
});
}
}
#[cfg(test)]
mod test {
use std::net::{IpAddr, Ipv4Addr};