Skip to main content

MfaManager

Struct MfaManager 

Source
pub struct MfaManager { /* private fields */ }
Expand description

MFA 管理器:管理用户的 MFA 密钥和验证状态

Implementations§

Source§

impl MfaManager

Source

pub fn new() -> Self

Source

pub fn generate_secret( &self, user_id: &str, account: impl Into<String>, issuer: impl Into<String>, ) -> MfaSecret

为用户生成新的 MFA 密钥

Source

pub fn bind_secret(&self, user_id: &str, secret: MfaSecret)

为用户绑定已有密钥

Source

pub fn verify(&self, user_id: &str, code: &str) -> Result<bool, AuthError>

验证用户的 TOTP 码

Source

pub fn generate_code(&self, user_id: &str) -> Result<String, AuthError>

生成用户当前的 TOTP 码(用于测试或重置流程)

Source

pub fn remove_secret(&self, user_id: &str) -> bool

移除用户的 MFA 密钥

Source

pub fn has_mfa(&self, user_id: &str) -> bool

检查用户是否已绑定 MFA

Source

pub fn get_uri(&self, user_id: &str) -> Result<String, AuthError>

获取用户 MFA 密钥的 otpauth URI

Trait Implementations§

Source§

impl Default for MfaManager

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.