Skip to content

Common OTP implementation in Shell, Python and Go

build your own 2FA/MFA app with Python, Go and Shell command.

Python

import pyotp
totp = pyotp.TOTP('XXXXXXXX')
print totp.now()

Golang

package main

import (
    "flag"
    "fmt"
    "strings"

    "github.com/hgfischer/go-otp"
)

var (
    length = flag.Uint("length", otp.DefaultLength, "OTP length")
    period = flag.Uint("period", otp.DefaultPeriod, "Period in seconds")
)

func main() {

    tokenMap := make(map[string]string)
    tokenMap["sso token"] = "XXXXXXXXX"

    for keyName, keyToken := range tokenMap {
        totp := &otp.TOTP{
            Secret:         strings.ToUpper(keyToken),
            Length:         uint8(*length),
            Period:         uint8(*period),
            IsBase32Secret: true,
        }
        fmt.Printf("%s: %s\n", keyName, totp.Get())
    }
}

Shell

## Debian & Ubuntu
apt install oathtool

## Mac 
brew install oathtool

oathtool -b --totp XXXXXXXXX

Disclaimer
  1. License under CC BY-NC 4.0
  2. Copyright issue feedback me#imzye.me, replace # with @
  3. Not all the commands and scripts are tested in production environment, use at your own risk
  4. No privacy information is collected here
Try iOS App