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
}
- View more examples and advanced usages @ pkg.go.dev
Statuses
Contributing
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
- MIT, Copyright (c) 2022 KEINOS and the go-totp contributors.
- This Go package relies heavily on support from the
github.com/pquerna/otp
package.