pub struct BruteForceGuard;Expand description
Guard untuk mencegah serangan Brute-Force & Credential Stuffing. Berjalan secara asynchronous, in-memory, dan lock-free menggunakan Moka Cache.
Implementations§
Source§impl BruteForceGuard
impl BruteForceGuard
Sourcepub async fn check(key: &str) -> Result<(), AppError>
pub async fn check(key: &str) -> Result<(), AppError>
Periksa apakah kunci (IP atau Email) saat ini sedang terkunci.
Mengembalikan Ok(()) jika aman, atau Err(AppError::Forbidden) jika sedang terkunci.
Sourcepub async fn check_with_config(
key: &str,
_config: &BruteForceConfig,
) -> Result<(), AppError>
pub async fn check_with_config( key: &str, _config: &BruteForceConfig, ) -> Result<(), AppError>
Periksa status kunci dengan konfigurasi kustom.
Sourcepub async fn hit(key: &str) -> u32
pub async fn hit(key: &str) -> u32
Catat percobaan gagal baru. Mengembalikan jumlah total kegagalan yang tercatat saat ini.
Sourcepub async fn hit_with_config(key: &str, config: &BruteForceConfig) -> u32
pub async fn hit_with_config(key: &str, config: &BruteForceConfig) -> u32
Catat percobaan gagal dengan konfigurasi kustom.
Sourcepub async fn is_locked(key: &str) -> bool
pub async fn is_locked(key: &str) -> bool
Periksa apakah kunci sedang dalam status terkunci (Boolean).
Sourcepub fn constant_time_eq(a: &str, b: &str) -> bool
pub fn constant_time_eq(a: &str, b: &str) -> bool
Helper verifikasi string dengan perbandingan waktu konstan (Constant-Time Comparison). Menggagalkan serangan Timing Attacks pada password hash, token, atau secret keys.
Auto Trait Implementations§
impl Forget for BruteForceGuard
impl Freeze for BruteForceGuard
impl Move for BruteForceGuard
impl RefUnwindSafe for BruteForceGuard
impl Send for BruteForceGuard
impl Sync for BruteForceGuard
impl Unpin for BruteForceGuard
impl UnsafeUnpin for BruteForceGuard
impl UnwindSafe for BruteForceGuard
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more