Giter Club home page Giter Club logo

google-authenticator-rust's Introduction

GoogleAuthenticator

Build Status Build Status

Introduction

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 More about Google GoogleAuthenticator see:Wiki

Usage

Add this to your Cargo.toml:

[dependencies]
google-authenticator = "0.2.0"

Examples

use google_authenticator::GoogleAuthenticator;

fn main() {
    let secret = "I3VFM3JKMNDJCDH5BMBEEQAW6KJ6NOE3";
    let auth = GoogleAuthenticator::new();
    // let secret = auth.create_secret(32);
    let code = auth.get_code(&secret, 0).unwrap();

    assert!(auth.verify_code(&secret, &code, 1, 0).unwrap());
}
#[macro_use]
extern crate google_authenticator;
use google_authenticator::GA_AUTH;

fn main() {
    let secret = "I3VFM3JKMNDJCDH5BMBEEQAW6KJ6NOE3";
    if let Ok(code) = get_code!(&secret) {
        println!("{}", verify_code!(&secret, &code, 1, 0));
    }
}

Get the secret QR code

Get Google Charts Url to make QR Code

use google_authenticator::{GoogleAuthenticator, ErrorCorrectionLevel};

fn main() {
    let auth = GoogleAuthenticator::new();
    let secret = "I3VFM3JKMNDJCDH5BMBEEQAW6KJ6NOE3";
    println!(
        "{}",
        auth.qr_code_url(secret, "qr_code", "name", 200, 200, ErrorCorrectionLevel::High)
    );
}
#[macro_use]
extern crate google_authenticator;
use google_authenticator::GA_AUTH;

fn main() {
    let secret = "I3VFM3JKMNDJCDH5BMBEEQAW6KJ6NOE3";
    println!("{}", qr_code_url!(&secret, "qr_code", "name"));
}

Get QR code image in svg format

Change Cargo.toml to

[dependencies.google-authenticator]
version = "0.1.9"
features = ["with-qrcode"]
use google_authenticator::{GoogleAuthenticator, ErrorCorrectionLevel};

fn main() {
    let secret = "I3VFM3JKMNDJCDH5BMBEEQAW6KJ6NOE3";
    let auth = GoogleAuthenticator::new();

    println!(
        "{}",
        auth.qr_code(secret, "qr_code", "name", 200, 200, ErrorCorrectionLevel::High)
            .unwrap()
    );
}
#[macro_use]
extern crate google_authenticator;
use google_authenticator::GA_AUTH;

fn main() {
    let secret = "I3VFM3JKMNDJCDH5BMBEEQAW6KJ6NOE3";
    if let Ok(url) = qr_code!(&secret, "qr_code", "name") {
        println!("{}", url);
    }
}

Contributors

Thanks to: JHZheng Conbas

FAQ

You can post a new issue for help.

google-authenticator-rust's People

Contributors

hanskorg avatar jtr109 avatar thoucheese avatar x1957 avatar zjhmale avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.