package hotp
import "git.sr.ht/~pingoo/stdx/otp/hotp"
Index ¶
- func Generate(opts GenerateOpts) (*otp.Key, error)
- func GenerateCode(secret string, counter uint64) (string, error)
- func GenerateCodeCustom(secret string, counter uint64, opts ValidateOpts) (passcode string, err error)
- func Validate(passcode string, counter uint64, secret string) bool
- func ValidateCustom(passcode string, counter uint64, secret string, opts ValidateOpts) (bool, error)
- type GenerateOpts
- type ValidateOpts
Functions ¶
func Generate ¶
func Generate(opts GenerateOpts) (*otp.Key, error)
Generate creates a new HOTP Key.
func GenerateCode ¶
GenerateCode creates a HOTP passcode given a counter and secret. This is a shortcut for GenerateCodeCustom, with parameters that are compataible with Google-Authenticator.
func GenerateCodeCustom ¶
func GenerateCodeCustom(secret string, counter uint64, opts ValidateOpts) (passcode string, err error)
GenerateCodeCustom uses a counter and secret value and options struct to create a passcode.
func Validate ¶
Validate a HOTP passcode given a counter and secret. This is a shortcut for ValidateCustom, with parameters that are compataible with Google-Authenticator.
func ValidateCustom ¶
func ValidateCustom(passcode string, counter uint64, secret string, opts ValidateOpts) (bool, error)
ValidateCustom validates an HOTP with customizable options. Most users should use Validate().
Types ¶
type GenerateOpts ¶
type GenerateOpts struct { // Name of the issuing Organization/Company. Issuer string // Name of the User's Account (eg, email address) AccountName string // Size in size of the generated Secret. Defaults to 10 bytes. SecretSize uint // Secret to store. Defaults to a randomly generated secret of SecretSize. You should generally leave this empty. Secret []byte // Digits to request. Defaults to 6. Digits otp.Digits // Algorithm to use for HMAC. Defaults to SHA1. Algorithm otp.Algorithm // Reader to use for generating HOTP Key. Rand io.Reader }
GenerateOpts provides options for .Generate()
type ValidateOpts ¶
type ValidateOpts struct { // Digits as part of the input. Defaults to 6. Digits otp.Digits // Algorithm to use for HMAC. Defaults to SHA1. Algorithm otp.Algorithm }
ValidateOpts provides options for ValidateCustom().
Source Files ¶
hotp.go
- Version
- v0.0.0-20240218134121-094174641f6e (latest)
- Published
- Feb 18, 2024
- Platform
- linux/amd64
- Imports
- 11 packages
- Last checked
- 4 months ago –
Tools for package owners.