pub struct UserAuthenticator { /* private fields */ }Expand description
User authentication manager.
Implementations§
Source§impl UserAuthenticator
impl UserAuthenticator
Sourcepub fn with_session_expiry(self, expiry: Duration) -> Self
pub fn with_session_expiry(self, expiry: Duration) -> Self
Create authenticator with custom session expiry.
Sourcepub fn with_max_failed_attempts(self, max: u32) -> Self
pub fn with_max_failed_attempts(self, max: u32) -> Self
Create authenticator with custom max failed attempts.
Sourcepub fn register_user(
&self,
_username: &str,
password: &str,
identity: UserIdentity,
) -> Result<String, SecurityError>
pub fn register_user( &self, _username: &str, password: &str, identity: UserIdentity, ) -> Result<String, SecurityError>
Register a new user with Password + TOTP authentication.
Returns the TOTP secret (base32 encoded) for the user to configure their authenticator app.
The username parameter is used as the lookup key - it should match identity.username.
Sourcepub fn authenticate(
&self,
username: &str,
credential: &Credential,
) -> Result<UserSession, SecurityError>
pub fn authenticate( &self, username: &str, credential: &Credential, ) -> Result<UserSession, SecurityError>
Authenticate a user and create a session.
Sourcepub fn authenticate_password_only(
&self,
username: &str,
password: &str,
) -> Result<UserSession, SecurityError>
pub fn authenticate_password_only( &self, username: &str, password: &str, ) -> Result<UserSession, SecurityError>
Authenticate without TOTP (for testing or initial setup).
WARNING: This should only be used in development/testing or when TOTP is being initially configured.
Sourcepub fn validate_session(
&self,
session_id: &SessionId,
) -> Result<UserIdentity, SecurityError>
pub fn validate_session( &self, session_id: &SessionId, ) -> Result<UserIdentity, SecurityError>
Validate a session and return the user identity.
Sourcepub fn get_session(&self, session_id: &SessionId) -> Option<UserSession>
pub fn get_session(&self, session_id: &SessionId) -> Option<UserSession>
Get a session by ID.
Sourcepub fn invalidate_session(&self, session_id: &SessionId)
pub fn invalidate_session(&self, session_id: &SessionId)
Invalidate (logout) a session.
Sourcepub fn invalidate_user_sessions(&self, username: &str)
pub fn invalidate_user_sessions(&self, username: &str)
Invalidate all sessions for a user.
Sourcepub fn cleanup_expired_sessions(&self)
pub fn cleanup_expired_sessions(&self)
Clean up expired sessions.
Sourcepub fn active_session_count(&self) -> usize
pub fn active_session_count(&self) -> usize
Get count of active sessions.
Sourcepub fn bind_session_to_device(
&self,
session_id: &SessionId,
device_id: DeviceId,
) -> Result<(), SecurityError>
pub fn bind_session_to_device( &self, session_id: &SessionId, device_id: DeviceId, ) -> Result<(), SecurityError>
Bind a session to a device.
Sourcepub fn unlock_account(&self, username: &str) -> Result<(), SecurityError>
pub fn unlock_account(&self, username: &str) -> Result<(), SecurityError>
Unlock a locked account (admin operation).
Sourcepub fn disable_account(&self, username: &str) -> Result<(), SecurityError>
pub fn disable_account(&self, username: &str) -> Result<(), SecurityError>
Disable an account (admin operation).
Sourcepub fn change_password(
&self,
user_name: &str,
old_password: &str,
new_password: &str,
) -> Result<(), SecurityError>
pub fn change_password( &self, user_name: &str, old_password: &str, new_password: &str, ) -> Result<(), SecurityError>
Change a user’s password.
Auto Trait Implementations§
impl Freeze for UserAuthenticator
impl !RefUnwindSafe for UserAuthenticator
impl Send for UserAuthenticator
impl Sync for UserAuthenticator
impl Unpin for UserAuthenticator
impl UnsafeUnpin for UserAuthenticator
impl !UnwindSafe for UserAuthenticator
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
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>
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>
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