Expand description
Two-factor authentication with one-time codes from an authenticator app, for Laravel for Rust.
Give a user a Secret, show it as a QR code, and check the codes their app shows:
use laravel_two_factor::{Secret, TwoFactor};
let two_factor = TwoFactor::default();
let secret = two_factor.generate_secret()?;
// Shown once, for the user to scan with their app.
let svg = two_factor.qr_code_svg(&secret, "taylor@example.com")?;
let code = two_factor.code(&secret);
assert!(two_factor.verify(&secret, &code));Structs§
- Recovery
Codes - One-time codes a user keeps for when their phone is gone. Each code logs in once.
- Secret
- The key an authenticator app and the server share, from which both derive the codes.
- TwoFactor
- Makes secrets, QR codes and codes, and checks the codes users type.
- TwoFactor
Config - How codes are made and checked.
- TwoFactor
Service Provider - Sets the default
TwoFactorConfig. Change it inwith_config:
Enums§
- Algorithm
- The hash function codes are derived with.
- Error
- What can go wrong with a secret, a config or a QR code.
Constants§
- ATTEMPTS_
PER_ MINUTE - The tries
TwoFactor::attemptallows per key each minute. - MAX_
PERIOD - The longest
TwoFactorConfig::period: a day, in seconds. - MIN_
SECRET_ BYTES - The fewest bytes a new secret may hold: 128 bits, the minimum RFC 4226 allows.
- MIN_
STORED_ SECRET_ BYTES - The fewest bytes an existing secret may hold: 80 bits, the 16 base32 characters Fortify and google2fa have long generated, so their users’ secrets keep working.