Documentation ¶
Overview ¶
Package otp provides one-time password authentication using both HMAC (HOTP) and time-based (TOTP) approaches.
Index ¶
Constants ¶
This section is empty.
Variables ¶
Supported hash algorithms.
Functions ¶
func GetCode ¶
GetCode returns a one-time password. The secret32 parameter is a Base32-encoded HMAC key. The iv parameter is the initialization value. The h parameter is a hash function to use in the HMAC. The digits parameter is the length of returned code.
Example:
code, err := GetCode("MFRGGZDFMZTWQ2LK", 1, sha1.New, 6)
func GetInterval ¶
GetInterval returns the unix epoch divided by period and the number of seconds remaining till expiration.
Types ¶
type Key ¶
type Key struct { Method string // Initialization method. Either 'totp' or 'hotp'. Label string // Descriptive label.. Secret32 string // Base32-encoded secret key. Issuer string // Key issuer. Algo Hash // Hash algorithm. See Hashes. Digits int // Length of the code. Either 6 or 8. Period int // Seconds code is valid for. Applies only to 'totp'. Counter int // Initial counter value. Applies only to 'hotp'. }
Key represents a one-time password. It supports time-based (totp) and HMAC-based (hotp) approaches.
func NewHOTPKey ¶
NewHOTPKey returns a hotp key struct.
func NewTOTPKey ¶
NewTOTPKey returns a totp key struct.
func (*Key) FromURI ¶
FromURI parses an otpauth URI into the key. Defaults are included for the hashing algorithm (sha1.New), digits (6), and period (30); these parameters may be excluded from the URI. The issuer is optional. For totp, only the method, label, and secret are required. See https://code.google.com/p/google-authenticator/wiki/KeyUriFormat for more information.
Example:
k.FromURI("otpauth://totp/Example:alice@google.com?algo=sha1&digits=6&issuer=Example&period=30&secret=NAR5XTDD3EQU22YU")