Skip to content

OTP implementation in Bash, Python & Go

homepage-banner

OTP Implementation in Python

install pyotp

pip install pyotp

demo python code

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

OTP Implementation in Go

install go-otp

go get github.com/xlzd/gotp

demo

package main

import (
    "fmt"
    "github.com/xlzd/gotp"
)

func main() {
    fmt.Println("Current OTP is", gotp.NewDefaultTOTP("XXXXXXXX").Now())
}

install totp-cli

go install github.com/agrinman/totp-cli@latest

totp-cli add "My Account" YOUR_SECRET
totp-cli list
totp-cli generate "My Account"

OTP Implementation in Shell

install oathtool

## Debian & Ubuntu
apt install oathtool

## CentOS & Fedora
sudo yum -y install oathtool
sudo dnf -y install oathtool

## Mac 
brew install oath-toolkit

demo command

oathtool -b --totp XXXXXXXXX

Reference

  • https://github.com/pquerna/otp
  • https://github.com/xlzd/gotp
  • https://www.nongnu.org/oath-toolkit/
  • https://www.ssl.com/article/what-is-a-one-time-password-otp/
  • https://www.linkedin.com/pulse/one-time-password-shekinah-t
  • https://tecadmin.net/how-to-install-and-configure-totp-cli-on-ubuntu/

Some of the content is generated by AI, please be cautious in identifying it.

Leave Your Message