Documentation ¶
Overview ¶
Package onetime provides a library for one-time password generation, implementing the HOTP and TOTP algorithms as specified by IETF RFC-4226 and RFC-6238.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Example_authenticator ¶
func Example_authenticator()
func Example_custom ¶
func Example_custom()
func Example_simple ¶
func Example_simple()
Types ¶
type OneTimePassword ¶
type OneTimePassword struct { Digit int // Length of code generated TimeStep time.Duration // Length of each time step for TOTP BaseTime time.Time // The start time for TOTP step calculation Hash func() hash.Hash // Hash algorithm used with HMAC }
OneTimePassword stores the configuration values relevant to HOTP/TOTP calculations.
func New ¶
func New(digit int) (otp OneTimePassword, err error)
New returns a new OneTimePassword with the specified HTOP code length, SHA-1 as the HMAC hash algorithm, the Unix epoch as the base time, and 30 seconds as the step length.
func (*OneTimePassword) GOTP ¶
func (otp *OneTimePassword) GOTP(secret string) (code string, err error)
GOTP returns a google authenticator style 6 digit OTP from a secret with 30 sec. interval time
func (*OneTimePassword) GTimeLeft ¶
func (otp *OneTimePassword) GTimeLeft() int
GTimeLeft returns the google authenticator style remaining time as integer
func (*OneTimePassword) HOTP ¶
func (otp *OneTimePassword) HOTP(secret []byte, count uint64) uint
HOTP returns a HOTP code with the given secret and counter.
func (*OneTimePassword) PPrint ¶
func (otp *OneTimePassword) PPrint(code string) string
Pprint returns a given code "pretty printed", i.e. divided in two or three blocks
func (*OneTimePassword) TOTP ¶
func (otp *OneTimePassword) TOTP(secret []byte) uint
TOTP returns a TOTP code calculated with the current time and the given secret.