pub struct TwoFactorSecret {
pub id: Uuid,
pub user_id: Uuid,
pub secret_encrypted: String,
pub backup_codes_encrypted: Vec<String>,
pub is_enabled: bool,
pub verified_at: Option<DateTime<Utc>>,
pub last_used_at: Option<DateTime<Utc>>,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
}Expand description
Two-factor authentication secret for TOTP (Time-based One-Time Password) Stores encrypted TOTP secret and backup codes for account recovery
Fields§
§id: Uuid§user_id: Uuid§secret_encrypted: String§backup_codes_encrypted: Vec<String>§is_enabled: bool§verified_at: Option<DateTime<Utc>>§last_used_at: Option<DateTime<Utc>>§created_at: DateTime<Utc>§updated_at: DateTime<Utc>Implementations§
Source§impl TwoFactorSecret
impl TwoFactorSecret
Sourcepub fn new(user_id: Uuid, secret_encrypted: String) -> Result<Self, String>
pub fn new(user_id: Uuid, secret_encrypted: String) -> Result<Self, String>
Create a new 2FA secret (not yet enabled)
Sourcepub fn with_backup_codes(
self,
backup_codes_encrypted: Vec<String>,
) -> Result<Self, String>
pub fn with_backup_codes( self, backup_codes_encrypted: Vec<String>, ) -> Result<Self, String>
Set backup codes (encrypted/hashed by caller)
Sourcepub fn regenerate_backup_codes(
&mut self,
new_backup_codes_encrypted: Vec<String>,
) -> Result<(), String>
pub fn regenerate_backup_codes( &mut self, new_backup_codes_encrypted: Vec<String>, ) -> Result<(), String>
Regenerate backup codes (caller must hash/encrypt new codes)
Sourcepub fn remove_backup_code(&mut self, code_index: usize) -> Result<(), String>
pub fn remove_backup_code(&mut self, code_index: usize) -> Result<(), String>
Remove a used backup code (caller must identify which code was used)
Sourcepub fn backup_codes_low(&self) -> bool
pub fn backup_codes_low(&self) -> bool
Check if backup codes are exhausted (< 3 remaining)
Sourcepub fn needs_reverification(&self) -> bool
pub fn needs_reverification(&self) -> bool
Check if 2FA needs re-verification (not used in 90 days)
Trait Implementations§
Source§impl Clone for TwoFactorSecret
impl Clone for TwoFactorSecret
Source§fn clone(&self) -> TwoFactorSecret
fn clone(&self) -> TwoFactorSecret
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 TwoFactorSecret
impl Debug for TwoFactorSecret
Source§impl<'de> Deserialize<'de> for TwoFactorSecret
impl<'de> Deserialize<'de> for TwoFactorSecret
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl From<TwoFactorSecret> for TwoFactorStatusDto
impl From<TwoFactorSecret> for TwoFactorStatusDto
Source§fn from(secret: TwoFactorSecret) -> Self
fn from(secret: TwoFactorSecret) -> Self
Converts to this type from the input type.
Source§impl PartialEq for TwoFactorSecret
impl PartialEq for TwoFactorSecret
Source§impl Serialize for TwoFactorSecret
impl Serialize for TwoFactorSecret
impl StructuralPartialEq for TwoFactorSecret
Auto Trait Implementations§
impl Freeze for TwoFactorSecret
impl RefUnwindSafe for TwoFactorSecret
impl Send for TwoFactorSecret
impl Sync for TwoFactorSecret
impl Unpin for TwoFactorSecret
impl UnwindSafe for TwoFactorSecret
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
§impl<T> Chain<T> for T
impl<T> Chain<T> for T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Fake for T
impl<T> Fake for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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 moreCreates a shared type from an unshared type.