pub struct TwoFactorConfig {
pub issuer: Option<String>,
pub digits: u32,
pub period: u64,
pub window: u64,
pub algorithm: Algorithm,
pub secret_bytes: usize,
pub cache_store: Option<String>,
}Expand description
How codes are made and checked.
The defaults are what every authenticator app shows. Each field reads from its TWO_FACTOR_*
variable:
use laravel_two_factor::TwoFactorConfig;
let config = TwoFactorConfig {
issuer: Some("Steddle".into()),
window: 0,
..TwoFactorConfig::default()
};Fields§
§issuer: Option<String>The name the app shows above the code, without a :. None uses APP_NAME.
digits: u32Digits per code: 6 to 8.
period: u64Seconds each code lasts, up to MAX_PERIOD.
window: u64Periods before and after the current one that also pass, for a phone whose clock is off.
algorithm: AlgorithmThe hash function codes are derived with.
secret_bytes: usizeBytes in a new secret, at least MIN_SECRET_BYTES.
cache_store: Option<String>The cache store verify_once keeps its marks in. None uses
the default store.
Implementations§
Source§impl TwoFactorConfig
impl TwoFactorConfig
Sourcepub fn from_env(env: &Env) -> Self
pub fn from_env(env: &Env) -> Self
Read the section from the environment, starting from its defaults.
| Field | Variable | Default |
|---|---|---|
issuer | TWO_FACTOR_ISSUER | none |
digits | TWO_FACTOR_DIGITS | 6 |
period | TWO_FACTOR_PERIOD | 30 |
window | TWO_FACTOR_WINDOW | 1 |
algorithm | TWO_FACTOR_ALGORITHM | Algorithm::Sha1 |
secret_bytes | TWO_FACTOR_SECRET_BYTES | 20 |
cache_store | TWO_FACTOR_CACHE_STORE | none |
from_env records invalid values and missing required values in env. Those problems
stop the application from starting.
Source§impl TwoFactorConfig
impl TwoFactorConfig
Sourcepub fn validate(&self) -> Result<(), Error>
pub fn validate(&self) -> Result<(), Error>
Checks that apps can show the codes this config makes.
§Errors
Fails when the issuer holds a :, digits is outside 6 to 8, period is outside 1 to
MAX_PERIOD seconds, window is over 10, or secret_bytes is below
MIN_SECRET_BYTES.
Trait Implementations§
Source§impl Clone for TwoFactorConfig
impl Clone for TwoFactorConfig
Source§impl Debug for TwoFactorConfig
impl Debug for TwoFactorConfig
Source§impl Default for TwoFactorConfig
impl Default for TwoFactorConfig
impl Eq for TwoFactorConfig
Source§impl PartialEq for TwoFactorConfig
impl PartialEq for TwoFactorConfig
impl StructuralPartialEq for TwoFactorConfig
Auto Trait Implementations§
impl Forget for TwoFactorConfig
impl Freeze for TwoFactorConfig
impl Move for TwoFactorConfig
impl RefUnwindSafe for TwoFactorConfig
impl Send for TwoFactorConfigwhere
RawVecInner: Send,
impl Sync for TwoFactorConfigwhere
RawVecInner: Sync,
impl Unpin for TwoFactorConfig
impl UnsafeUnpin for TwoFactorConfig
impl UnwindSafe for TwoFactorConfigwhere
RawVecInner: UnwindSafe,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.