go1.15+ Go Reference

go-totp

go-totp is a simple Go package to implement Timebased-One-Time-Password authentication functionality, a.k.a. TOTP, to the Go app.

Note This is a wrapper of the awesome github.com/pquerna/otp package to facilitate the use of TOTP.

go get "github.com/rodrigodiez/go-totp"

import (
    "fmt"
    "log"

    "github.com/KEINOS/go-totp/totp"
)

func Example() {
    // Generate a new secret key
    Issuer := "Example.com"
    AccountName := "[email protected]"

    key, err := totp.GenerateKey(Issuer, AccountName)
    if err != nil {
        log.Fatal(err)
    }

    // Generate 6 digits passcode (valid for 30 seconds)
    passcode, err := key.PassCode()
    if err != nil {
        log.Fatal(err)
    }

    // Validate the passcode
    valid, err := key.Validate(passcode)
    if err != nil {
        log.Fatal(err)
    }

    if valid {
        fmt.Println("Passcode is valid")
    }

    // Output: Passcode is valid
}

Statuses

UnitTests golangci-lint CodeQL-Analysis PlatformTests

codecov Go Report Card

Contributing

go1.15+ Go Reference Opened Issues PR

Any Pull-Request for improvement is welcome!

  • Branch to PR: main
  • CIs on PR/Push: unit-tests golangci-lint codeQL-analysis platform-tests
  • Security policy

License, copyright and credits

GitHub

View Github