Documentation
¶
Overview ¶
Package gootp is a one time password implementation of RFC 6238 (TOTP) and RFC 4226 (HOTP)
Index ¶
- func GenerateOTPSecret(s int) (string, error)
- func HOTP(secret string, count int64, h func() hash.Hash, digits int) (otp string, err error)
- func TOTPAt(secret string, t time.Time, h func() hash.Hash, digits int) (otp string, timeRemaining int, err error)
- func TOTPHistory(secret string, h func() hash.Hash, digits int, history int) (otps []string, timeRemaining int, err error)
- func TOTPNow(secret string, h func() hash.Hash, digits int) (otp string, timeRemaining int, err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateOTPSecret ¶
GenerateOTPSecret returns a base32 encoded secret string to be shared between the client and the server for OTPs.
Specify the length of the secret to generate in bytes. Note this needs to be at least 16 bytes / 128 bits.
func HOTP ¶
HOTP returns the HMAC-based One Time Password (RFC 4226). Providing the following inputs:
- Secret string at least 16 bytes / 128 bits in length
- Counter value, the moving factor (see RFC 4226 section 5.2). This counter MUST be synchronized between the HOTP generator (client) and the HOTP validator (server).
- A hash function to use, eg SHA1, SHA256, SHA512
- The number of digits to be returned in the OTP. Must be a minimum of 6.
Note that the returned OTP is a string as a leading zero is valid so an integer type is not appropriate
func TOTPAt ¶
func TOTPAt(secret string, t time.Time, h func() hash.Hash, digits int) (otp string, timeRemaining int, err error)
TOTPAt returns the Time-based One Time Password (RFC 6238) for a specific time. Providing the following inputs:
- Secret string at least 16 bytes / 128 bits in length.
- The UTC time for which the TOTP should be generated.
- A hash function to use, eg SHA1, SHA256, SHA512.
- The number of digits to be returned in the OTP. Must be a minimum of 6.
Note that the returned OTP is a string as a leading zero is valid so an integer type is not appropriate.
The number of seconds the OTP is valid for is also returned.
func TOTPHistory ¶
func TOTPHistory(secret string, h func() hash.Hash, digits int, history int) (otps []string, timeRemaining int, err error)
TOTPHistory returns a Time-based One Time Password history (RFC 6238). Providing the following inputs:
- Secret string at least 16 bytes / 128 bits in length.
- A hash function to use, eg SHA1, SHA256, SHA512.
- The number of digits to be returned in the OTP. Must be a minimum of 6.
Note that the returned OTP is an array of strings as a leading zero is valid so an integer type is not appropriate. The first element in the array is the current OTP.
The number of seconds the current OTP is valid for is also returned.
func TOTPNow ¶
func TOTPNow(secret string, h func() hash.Hash, digits int) (otp string, timeRemaining int, err error)
TOTPNow returns the Time-based One Time Password (RFC 6238) for the current time. Providing the following inputs:
- Secret string at least 16 bytes / 128 bits in length.
- A hash function to use, eg SHA1, SHA256, SHA512.
- The number of digits to be returned in the OTP. Must be a minimum of 6.
Note that the returned OTP is a string as a leading zero is valid so an integer type is not appropriate.
The number of seconds the OTP is valid for is also returned.
Types ¶
This section is empty.