Common OTP implementation in Shell, Python and Go
build your own 2FA/MFA app with
Python
,Go
andShell
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
- License under
CC BY-NC 4.0
- Copyright issue feedback
me#imzye.me
, replace # with @ - Not all the commands and scripts are tested in production environment, use at your own risk
- No privacy information is collected here