Documentation
¶
Index ¶
- Constants
- func BuildURL(issuer, accountName, secret string) string
- func GenerateCode(secret string, t time.Time) (string, error)
- func GenerateHOTP(key []byte, counter uint64) string
- func GenerateRecoveryCodes(count int) ([]string, error)
- func GenerateSecret() (string, error)
- func GenerateSecretWithLength(numBytes int) (string, error)
- func HashRecoveryCode(code string, pepper []byte) string
- func NormalizeRecoveryCode(code string) string
- func Validate(passcode, secret string) bool
- func ValidateCustom(passcode, secret string, t time.Time, skew int) (bool, int64)
- func ValidateWithStep(passcode, secret string) (bool, int64)
Constants ¶
const ( // DefaultPeriod is the standard TOTP time-step duration (30 seconds). DefaultPeriod = 30 * time.Second // DefaultDigits is the standard number of digits in a TOTP passcode. DefaultDigits = 6 // DefaultSkew is the number of adjacent intervals allowed before and after current time. DefaultSkew = 1 )
Variables ¶
This section is empty.
Functions ¶
func GenerateCode ¶
GenerateCode computes the 6-digit TOTP passcode for a given secret at the specified time.
func GenerateHOTP ¶
GenerateHOTP computes an RFC 4226 HMAC-SHA1 passcode for a given counter.
func GenerateRecoveryCodes ¶
GenerateRecoveryCodes generates count random recovery codes formatted as xxxx-xxxx.
func GenerateSecret ¶
GenerateSecret creates a 20-byte base32 secret.
func GenerateSecretWithLength ¶
GenerateSecretWithLength creates a base32 secret with the specified byte length.
func HashRecoveryCode ¶
HashRecoveryCode hashes the normalized recovery code with HMAC-SHA256 using a server pepper.
func NormalizeRecoveryCode ¶
NormalizeRecoveryCode strips hyphens and whitespace and converts the code to lowercase.
func Validate ¶
Validate checks if a 6-digit TOTP passcode matches the secret within the default skew window.
func ValidateCustom ¶
ValidateCustom validates a passcode against a specific timestamp and skew window.
func ValidateWithStep ¶
ValidateWithStep checks if a passcode matches the secret and returns the matching time-step counter.
Types ¶
This section is empty.