pub struct RecoveryCodes { /* private fields */ }Expand description
A freshly generated set of recovery codes, in the clear.
The one moment they exist readably. Show them once, tell the person to print
them, store only hashed — exactly like a password, and for
the same reason: each one is a complete bypass of the second factor.
Implementations§
Source§impl RecoveryCodes
impl RecoveryCodes
Sourcepub fn generate(count: usize) -> RecoveryCodes
pub fn generate(count: usize) -> RecoveryCodes
Mint count codes. Ten is the usual number, and what Laravel issues.
pub fn into_codes(self) -> Vec<String>
Sourcepub fn hashed(&self) -> Vec<String>
pub fn hashed(&self) -> Vec<String>
What to store: an argon2 hash of each code.
Argon2 rather than SHA-256, unlike crate::tokens, and the difference
is deliberate. An API token is 256 bits of CSPRNG output, so there is
nothing to search; a recovery code is fifty bits and is typed by a
person, which means it may well be written down, photographed, or
entered into the wrong box. Fifty bits is beyond an online attacker but
it is not beyond somebody who has stolen the table, and a KDF is what
makes the difference. They are also verified once, on a rare path, so
the cost buys the protection without being felt.
Sourcepub fn hashed_with(&self, cost: Cost) -> Vec<String>
pub fn hashed_with(&self, cost: Cost) -> Vec<String>
hashed at an explicit cost, for tests. See
Cost::FAST, and do not store real codes hashed with it.