Expand description
Authentication middleware for the web dashboard.
This module provides authentication functionality including basic auth verification, rate limiting for failed attempts, and account lockout mechanisms.
§Examples
§Basic Authentication Setup
use hammerwork_web::auth::{AuthState, extract_basic_auth};
use hammerwork_web::config::AuthConfig;
let auth_config = AuthConfig {
enabled: true,
username: "admin".to_string(),
password_hash: "plain_password".to_string(), // Use bcrypt in production
..Default::default()
};
let auth_state = AuthState::new(auth_config);
assert!(auth_state.is_enabled());§Extracting Basic Auth Credentials
use hammerwork_web::auth::extract_basic_auth;
// "admin:password" in base64 is "YWRtaW46cGFzc3dvcmQ="
let auth_header = "Basic YWRtaW46cGFzc3dvcmQ=";
let (username, password) = extract_basic_auth(auth_header).unwrap();
assert_eq!(username, "admin");
assert_eq!(password, "password");
// Invalid format returns None
let result = extract_basic_auth("Bearer token123");
assert!(result.is_none());Structs§
- Auth
State - Authentication middleware state
Enums§
- Auth
Error - Custom authentication errors
Functions§
- auth_
filter - Authentication filter for Warp
- extract_
basic_ auth - Extract basic auth credentials from request.
- handle_
auth_ rejection - Handle authentication rejections