Automatically clean failed login attempts
This commit is contained in:
@@ -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};
|
||||
|
Reference in New Issue
Block a user