[−][src]Struct google_authenticator::GoogleAuthenticator
The main interface of this library. It exports several function that are necessary to interface with google authenticator.
Implementations
impl GoogleAuthenticator
[src]
pub fn new() -> Self
[src]
Create a new GoogleAuthenticator
using the default implementation. This means that the
codes generated have a length of 6 and the secret will be chosen from allowed base32
characters.
Example
use google_authenticator::GoogleAuthenticator; let auth = GoogleAuthenticator::new();
pub fn with_code_length(self, code_length: usize) -> Self
[src]
Use this method to configure the length of the generated code.
Example
use google_authenticator::GoogleAuthenticator; let auth = GoogleAuthenticator::new() .with_code_length(8);
pub fn create_secret(&self, length: u8) -> String
[src]
Create new secret.
Example:
use google_authenticator::GoogleAuthenticator; let google_authenticator = GoogleAuthenticator::new(); google_authenticator.create_secret(32);
pub fn get_code(&self, secret: &str, times_slice: u64) -> Result<String>
[src]
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();
pub fn verify_code(
&self,
secret: &str,
code: &str,
discrepancy: u64,
time_slice: u64
) -> bool
[src]
&self,
secret: &str,
code: &str,
discrepancy: u64,
time_slice: u64
) -> bool
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);
pub fn qr_code_url(
&self,
secret: &str,
name: &str,
title: &str,
width: u32,
height: u32,
level: ErrorCorrectionLevel
) -> String
[src]
&self,
secret: &str,
name: &str,
title: &str,
width: u32,
height: u32,
level: ErrorCorrectionLevel
) -> String
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
impl Default for GoogleAuthenticator
[src]
Auto Trait Implementations
impl RefUnwindSafe for GoogleAuthenticator
impl Send for GoogleAuthenticator
impl Sync for GoogleAuthenticator
impl Unpin for GoogleAuthenticator
impl UnwindSafe for GoogleAuthenticator
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,