pub struct MemoryAuth { /* private fields */ }Expand description
Simple in-memory authentication backend using a hash set.
This is suitable for small deployments with a fixed set of users. For dynamic user management or large user bases, consider using a database-backed backend.
Implementations§
Source§impl MemoryAuth
impl MemoryAuth
Sourcepub fn from_hashes<I, S>(hashes: I) -> Self
pub fn from_hashes<I, S>(hashes: I) -> Self
Create from pre-computed SHA224 hashes.
§Example
use trojan_auth::MemoryAuth;
let auth = MemoryAuth::from_hashes(["abc123...", "def456..."]);Sourcepub fn from_passwords<I, S>(passwords: I) -> Self
pub fn from_passwords<I, S>(passwords: I) -> Self
Create from plaintext passwords (will be hashed).
§Example
use trojan_auth::MemoryAuth;
let auth = MemoryAuth::from_passwords(["password1", "password2"]);Sourcepub fn from_passwords_with_ids<I, P, U>(pairs: I) -> Self
pub fn from_passwords_with_ids<I, P, U>(pairs: I) -> Self
Create from password-to-user-id pairs.
§Example
use trojan_auth::MemoryAuth;
let auth = MemoryAuth::from_passwords_with_ids([
("password1", "user1"),
("password2", "user2"),
]);Sourcepub fn add_password(&mut self, password: &str, user_id: Option<String>)
pub fn add_password(&mut self, password: &str, user_id: Option<String>)
Add a user with a plaintext password.
Sourcepub fn add_hash(&mut self, hash: String, user_id: Option<String>)
pub fn add_hash(&mut self, hash: String, user_id: Option<String>)
Add a user with a pre-computed hash.
Sourcepub fn remove_hash(&mut self, hash: &str) -> bool
pub fn remove_hash(&mut self, hash: &str) -> bool
Remove a user by hash.
Trait Implementations§
Source§impl AuthBackend for MemoryAuth
impl AuthBackend for MemoryAuth
Source§fn verify<'life0, 'life1, 'async_trait>(
&'life0 self,
hash: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<AuthResult, AuthError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn verify<'life0, 'life1, 'async_trait>(
&'life0 self,
hash: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<AuthResult, AuthError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Verify a password hash. Read more
Source§fn record_traffic<'life0, 'life1, 'async_trait>(
&'life0 self,
_user_id: &'life1 str,
_bytes: u64,
) -> Pin<Box<dyn Future<Output = Result<(), AuthError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn record_traffic<'life0, 'life1, 'async_trait>(
&'life0 self,
_user_id: &'life1 str,
_bytes: u64,
) -> Pin<Box<dyn Future<Output = Result<(), AuthError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Optional: Record traffic usage for a user. Read more
Source§impl Clone for MemoryAuth
impl Clone for MemoryAuth
Source§fn clone(&self) -> MemoryAuth
fn clone(&self) -> MemoryAuth
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for MemoryAuth
impl Debug for MemoryAuth
Auto Trait Implementations§
impl Freeze for MemoryAuth
impl RefUnwindSafe for MemoryAuth
impl Send for MemoryAuth
impl Sync for MemoryAuth
impl Unpin for MemoryAuth
impl UnwindSafe for MemoryAuth
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