Struct google_authenticator::GA_AUTH[][src]

pub struct GA_AUTH { /* fields omitted */ }
Expand description

A globally accessible, thread safe instance of a GoogleAuthenticator. Note that if the code panics while this variable is in scope, the std::sync::Mutex can be poisoned, preventing further access to this variable.

Methods from Deref<Target = GoogleAuthenticator>

Create new secret.

Example:

use google_authenticator::GoogleAuthenticator;

let google_authenticator = GoogleAuthenticator::new();
google_authenticator.create_secret(32);

Calculate the code, with given secret and point in time. The secret parameter is the secret configured for this user. The times_slice parameter is the unix timestamp divided by 30 at which the code should expire.

Example
use google_authenticator::GoogleAuthenticator;

let authenticator = GoogleAuthenticator::new();
authenticator.get_code("I3VFM3JKMNDJCDH5BMBEEQAW6KJ6NOE3", 1523610659 / 30).unwrap();

This function verifies that a provided code is correct. The parameter secret is used to verify the user. code is the code that will be verified. The parameter discrepancy indicates number of seconds ago that a code may be generated. time_slice is used to modify what the current time is, as a unix timestamp. If 0 is provided here, the current time will be used.

Example
use google_authenticator::GoogleAuthenticator;

let authenticator = GoogleAuthenticator::new();
authenticator.verify_code("I3VFM3JKMNDJCDH5BMBEEQAW6KJ6NOE3", "224124", 3, 1523610659 / 30);

Get QR-Code URL for image, from google charts. For the height and width, if a value of 0 is provided, the default of 200px is used. Level is the amount of fault tolerance that the QR code should accept, see this page for more information.

Example
use google_authenticator::{GoogleAuthenticator, ErrorCorrectionLevel};

let authenticator = GoogleAuthenticator::new();
authenticator.qr_code_url(
    "I3VFM3JKMNDJCDH5BMBEEQAW6KJ6NOE3",
    "your company name",
    "hello",
    0,
    0,
    ErrorCorrectionLevel::Medium,
);

Trait Implementations

The resulting type after dereferencing.

Dereferences the value.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.