Skip to content

JonathanMcCormickJr/easy_totp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

easy_totp

TOTP in Rust, but with just a few simple functions to call.

BEWARE: handle secrets with caution

Creating a QR code for TOTP setup

use easy_totp::EasyTotp;

let raw_secret = String::from("SUPERSecretSecretSecret");
let issuer = Some(String::from("McCormick"));
let account_name = String::from("test@test-email.com");

let my_qr_code = EasyTotp::create_qr_png(raw_secret, issuer, account_name);

Rendering that QR code in the terminal

use easy_totp::EasyTotp;
let raw_secret = String::from("SUPERSecretSecretSecret");
let issuer = Some(String::from("McCormick"));
let account_name = String::from("test@test-email.com");
EasyTotp::render_qr_terminal(raw_secret, issuer, account_name).unwrap();

That will print out a QR code in the terminal that you can potentially scan with your authenticator app. Your mileage may vary.

Example authenticator apps and whether they can scan from terminal output

  • ✔️ Aegis Authenticator (Android)
  • ✔️ Bitwarden Authenticator (Android)
  • ✔️ Proton Authenticator (Android)
  • ✔️ Google Authenticator (Android)
██████████████████████████████████████████████████████████████████████████████████████████████████████████████████
██████████████████████████████████████████████████████████████████████████████████████████████████████████████████
██████████████████████████████████████████████████████████████████████████████████████████████████████████████████
██████████████████████████████████████████████████████████████████████████████████████████████████████████████████
████████              ████        ██      ██      ██████            ████  ██  ████  ████  ██              ████████
████████  ██████████  ████████        ██  ██      ██  ██  ██████  ██        ██  ██        ██  ██████████  ████████
████████  ██      ██  ██    ██████████████    ██  ██████  ████  ████████  ██  ████████    ██  ██      ██  ████████
████████  ██      ██  ██        ██        ████████      ██    ████      ████████    ██  ████  ██      ██  ████████
████████  ██      ██  ██  ██████    ██                        ██      ██  ████      ████████  ██      ██  ████████
████████  ██████████  ██  ████  ██  ████████████  ██  ██████    ██████████    ████    ██████  ██████████  ████████
████████              ██  ██  ██  ██  ██  ██  ██  ██  ██  ██  ██  ██  ██  ██  ██  ██  ██  ██              ████████
████████████████████████    ██    ██  ████  ██        ██████  ██████    ████    ████████  ████████████████████████
████████  ██          ████  ████  ██████    ████              ████████  ████████          ██          ████████████
████████  ████      ██    ██  ████  ████        ██  ██████  ████        ████████    ██████          ██████████████
████████████████████  ██    ██          ██████  ██      ██      ████  ████  ██    ██  ██    ██    ██      ████████
██████████    ██    ████        ██████  ██      ██  ██  ██  ████  ██████  ██████    ██  ██    ████████    ████████
████████  ██████      ████  ████  ██  ████      ██    ██      ████      ██        ████  ████    ██████  ██████████
██████████  ██████  ████      ████      ██    ████  ██      ██████      ██████  ██  ██████    ██  ██    ██████████
████████████████  ██      ██████    ████        ████████  ████████  ██          ██████  ██████████████    ████████
████████████████    ██  ████    ██      ██    ████  ████  ██  ██████    ██  ██    ██  ██  ██  ██  ████  ██████████
██████████████  ████  ████████████████    ████    ████    ████  ██    ██████████      ██    ██  ██  ██  ██████████
████████  ██  ██  ██████  ██████████████    ██  ████████    ████████    ██  ██    ████████    ██  ████  ██████████
████████████████        ████        ██████  ██      ██    ████  ██    ██████████  ██████  ████      ████  ████████
██████████    ██  ████  ██  ██  ██████    ██  ████████  ████████████        ████    ████          ████████████████
████████      ██████  ████        ██████  ██  ████    ██    ██████  ██  ████      ████    ████  ████  ██  ████████
████████████  ██    ██    ██  ██████  ████      ████  ██  ████████        ██████    ██  ██      ██  ██  ██████████
████████████              ██        ██      ██    ██          ██  ████      ████████  ██          ██████  ████████
████████████  ██  ██████    ██    ████  ████    ████  ██████  ████████████      ██  ████  ██████  ████    ████████
████████    ██    ██  ██    ██    ██  ██████  ██      ██  ██  ████  ██  ████        ████  ██  ██      ████████████
████████████      ██████  ██  ████  ██    ██████████  ██████          ██  ████      ████  ██████    ██████████████
██████████                ████        ██    ██████            ██        ██  ██    ██              ██      ████████
████████    ██████  ██  ██      ████  ██  ██    ██          ██        ██    ██████    ██  ██    ██████    ████████
████████████  ██            ██████  ██      ████████        ████████    ████████          ██  ██    ██    ████████
██████████  ██    ████        ██  ██        ██      ████  ████  ██    ██  ██████    ██  ██████  ████  ████████████
████████      ██  ██        ██    ██  ██  ██████  ██      ████████████████    ██  ████████        ████    ████████
████████  ██        ████████  ████████  ██████    ██████  ██    ██  ████████  ██          ████████████    ████████
████████  ████  ████  ████  ████  ██      ████    ██    ██  ████  ████          ████    ██████          ██████████
████████  ██      ████  ██████    ██  ██  ████  ████████            ████  ██  ████    ██████  ████  ██  ██████████
████████████  ██      ██      ████    ████████            ██████  ██        ██  ████████  ██  ██    ██    ████████
████████  ██    ██  ██            ████  ██  ██████  ██        ██  ██████    ██        ████  ██  ██████    ████████
████████  ██      ██  ████  ████    ██  ██      ██        ████  ██  ██  ████                ████          ████████
████████  ██        ██      ██      ██████  ██  ██          ████████      ████  ██  ██      ██████        ████████
██████████  ██████      ████████  ██    ██  ████  ██  ██  ██████    ██  ██    ██      ████    ████████    ████████
██████████      ████████  ██    ██  ██        ██                ████    ████  ████████████████    ████  ██████████
████████      ██████    ██████  ████████    ██                ████  ██  ██                            ████████████
████████████████████████  ██████  ████          ████  ██████  ██          ████████  ██    ██████  ██  ████████████
████████              ████        ██  ████  ██        ██  ██      ██  ██    ████      ██  ██  ██  ████    ████████
████████  ██████████  ██    ██████████████████████    ██████  ██  ████    ██    ████      ██████  ████    ████████
████████  ██      ██  ██      ████  ██  ██████  ████          ██████    ██  ██    ██  ██          ████  ██████████
████████  ██      ██  ██  ████  ████████    ██████  ██  ██                ██████    ██              ██  ██████████
████████  ██      ██  ██    ██    ██  ████      ██    ██  ██      ████              ██████  ██  ████      ████████
████████  ██████████  ████                  ██████████        ██████    ██  ██    ████████      ████████  ████████
████████              ██  ████    ██  ██  ██      ████    ████  ██    ██████████    ████      ████  ██    ████████
██████████████████████████████████████████████████████████████████████████████████████████████████████████████████
██████████████████████████████████████████████████████████████████████████████████████████████████████████████████
██████████████████████████████████████████████████████████████████████████████████████████████████████████████████
██████████████████████████████████████████████████████████████████████████████████████████████████████████████████
Scan the above QR code with your authenticator app to set up TOTP.
BEWARE: this QR code contains your secret key! Handle with care.
Useful tips: if scanning fails, try inverting the QR code colors by adjusting your terminal's background color or 
using your mouse to select the entire QR code area. Also, ensure your terminal zoom is set to a level that allows 
the QR code to be completely visible onscreen.
                                               

Saving that QR code to a file

use easy_totp::EasyTotp;
use std::fs;
use std::io::Write;

let raw_secret = String::from("SUPERSecretSecretSecret");
let issuer = Some(String::from("McCormick"));
let account_name = String::from("test@test-email.com");
let filename = "./test_images/qr_code.png";

let my_qr_code = EasyTotp::create_qr_png(raw_secret, issuer, account_name);

match my_qr_code {
    Ok(png_data) => {
        let mut file = fs::File::create(filename).unwrap();
        file.write_all(&png_data).unwrap();
        println!("QR code saved as 'qr_code.png'");
    }
    Err(e) => {
        panic!("Error creating QR code: {:?}", e);
    }
}

Generating TOTP codes for authentication

use easy_totp::EasyTotp;

let raw_secret = String::from("SUPERSecretSecretSecret");
let issuer = Some(String::from("McCormick"));
let account_name = String::from("test@test-email.com");

let token = EasyTotp::generate_token(raw_secret, issuer, account_name).unwrap();

About

TOTP in Rust, but with just a few simple functions to call.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages