Skip to content

cristalhq/otp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

3761d84 · Nov 16, 2024

History

37 Commits
Mar 3, 2024
Apr 22, 2022
Apr 11, 2022
Apr 18, 2022
Dec 2, 2023
Apr 11, 2022
Jun 28, 2024
Dec 2, 2023
Jun 28, 2024
Jun 28, 2024
Nov 16, 2024
Dec 2, 2023

Repository files navigation

otp

build-img pkg-img reportcard-img coverage-img version-img

One time password for Go.

Features

  • Simple API.
  • Dependency-free.
  • Clean and tested code.
  • HOTP RFC 4226.
  • TOTP RFC 6238.

See GUIDE.md for more details.

Install

Go version 1.17+

go get github.com/cristalhq/otp

Example

secretInBase32 := "JBSWY3DPEHPK3PXP"

algo := otp.AlgorithmSHA1
digits := otp.Digits(10)
issuer := "cristalhq"

hotp, err := otp.NewHOTP(algo, digits, issuer)
checkErr(err)

code, err := hotp.GenerateCode(42, secretInBase32)
checkErr(err)

fmt.Println(code)

err = hotp.Validate(code, 42, secretInBase32)
checkErr(err)

// Output:
// 0979090604

Also see examples: examples_test.go.

Documentation

See these docs.

License

MIT License.