Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
New generate a TOTP code.
Example ¶
package main import ( "fmt" "github.com/lucasepe/totp" ) func main() { // Verify with: https://totp.danhersam.com/ code, err := totp.New(totp.Options{ Secret: "JBSWY3DPEHPK3PXP", Digits: 8, Period: 15, UnixTime: 32158800000, }) if err != nil { fmt.Println(err.Error()) } fmt.Println(code) }
Output: 45451783
Types ¶
type Options ¶
type Options struct { Secret string // Secret key (required) Digits int // OTP digit count (default: 6) Algorithm string // OTP Algorithm ("SHA1" or "SHA256" or "SHA512") (default: SHA1) Period int64 // Period for which OTP is valid (seconds) (default: 30) UnixTime int64 // (Optional) Unix Timestamp (default: Current unix timestamp) }
Options represents Time-based OTP. See https://datatracker.ietf.org/doc/html/rfc6238
func ParseURI ¶
Example ¶
package main import ( "fmt" "github.com/lucasepe/totp" ) func main() { opts, err := totp.ParseURI("otpauth://totp/Acme?secret=IRXW4J3UEBKGK3DMEBAW46KPNZSSC") if err != nil { panic(err) } // This only to be sure to generate always the same code. opts.UnixTime = int64(32158800) code, err := totp.New(opts) if err != nil { panic(err) } fmt.Println(code) }
Output: 331676
Click to show internal directories.
Click to hide internal directories.