Expand description
This Rust crate can be used to interact with the Google Authenticator mobile app for 2-factor-authentication. This Rust crates can generate secrets, generate codes, validate codes and present a QR-Code for scanning the secret. It implements TOTP according to RFC6238
§Examples
use google_authenticator::GoogleAuthenticator;
let secret = "I3VFM3JKMNDJCDH5BMBEEQAW6KJ6NOE3";
let auth = GoogleAuthenticator::new();
let code = auth.get_code(secret,0).unwrap();
if auth.verify_code(secret, code.as_str(), 1, 0) {
println!("match!");
}Macros§
- create_
secret - A macro that can be used for convenient access to the function
GoogleAuthenticator::create_secret, by providing a default of32to thelengthparameter. - get_
code - A macro that can be used for convenient access to the function
GoogleAuthenticator::get_code, by providing a default of the current time to thetimes_sliceparameter. - qr_code
- A macro that can be used for convenient access to the function
GoogleAuthenticator::qr_code, by providing a default of 200 to thewidthparameter, 200 to theheightparameter, andErrorCorrectionLevel::Mediumto thelevelparameter. - qr_
code_ url - A macro that can be used for convenient access to the function
GoogleAuthenticator::qr_code_url, by providing a default of 200 to thewidthparameter, 200 to theheightparameter, andErrorCorrectionLevel::Mediumto thelevelparameter. - verify_
code - A macro that can be used for convenient access to the function
GoogleAuthenticator::verify_code, by providing a default of 0 to thediscrepancyparameter, and the current time to thetimes_sliceparameter.
Structs§
- GA_AUTH
- A globally accessible, thread safe instance of a
GoogleAuthenticator. Note that if the code panics while this variable is in scope, thestd::sync::Mutexcan be poisoned, preventing further access to this variable. - Google
Authenticator - The main interface of this library. It exports several function that are necessary to interface with google authenticator.
Enums§
- Error
Correction Level - Controls the amount of fault tolerance that the QR code should accept. Require the feature
flag
with-qrcode. - GAError
- Represents any of the reasons why using 2fa with Google Authenenticator can fail.
Type Aliases§
- Result
- A type alias that can be used for fallible functions with
google_authenticator.