Skip to main content

Crate laravel_two_factor

Crate laravel_two_factor 

Source
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§

RecoveryCodes
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.
TwoFactorConfig
How codes are made and checked.
TwoFactorServiceProvider
Sets the default TwoFactorConfig. Change it in with_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::attempt allows 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.