Documentation
¶
Overview ¶
Package totp uses, creates or verifies time based one-time-passwords based on the specification in RFC6238¹. Digest hasher function sha512 and 8 digits are used by default by Now().
¹ https://www.rfc-editor.org/rfc/rfc6238.html
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
Functions ¶
Types ¶
type Code ¶
type Code string
Code represents the generated TOTP token.
func Now ¶
Now returns a code for the given secret, using sha512 and 8 digits on 30 seconds.
Example ¶
package main import ( "fmt" "catinello.eu/totp" ) var ( MySecret string ThisCode totp.Code ) func main() { ThisCode = totp.Now(MySecret) fmt.Println(len(ThisCode)) }
Output: 8
type TOTP ¶
type TOTP struct {
// contains filtered or unexported fields
}
TOTP contains all attributes and values.
func New ¶
New returns a TOTP with the given attributes.
Example ¶
package main import ( "fmt" "log" "time" "catinello.eu/totp" ) var MySecret string func main() { token, err := totp.New(MySecret, 8, nil, 30) if err != nil { log.Fatal(err) } code, err := token.Generate(time.Now()) if err != nil { log.Fatal(err) } fmt.Println(code) }
Output:
func (*TOTP) Generate ¶
Generate returns a code for the given date and TOTP.
Example ¶
package main import ( "fmt" "log" "time" "catinello.eu/totp" ) var Token totp.TOTP func main() { code, err := Token.Generate(time.Now()) if err != nil { log.Fatal(err) } fmt.Println(len(code)) }
Output: 8
func (*TOTP) Verify ¶
Verify takes a date and code value to compare against a generated token.
Example ¶
package main import ( "fmt" "log" "time" "catinello.eu/totp" ) var ( Token totp.TOTP ThisCode totp.Code ) func main() { comp, err := Token.Verify(time.Now(), ThisCode) if err != nil { log.Fatal(err) } fmt.Println(comp) }
Output: true
Click to show internal directories.
Click to hide internal directories.