Documentation ¶
Overview ¶
Package basicOTP implements One-Time Password (OTP) generation according to RFC 4226 and RFC 6238. It provides functionality to generate OTP codes using HMAC-based algorithms like SHA-1, SHA-256, and SHA-512. This package is useful for implementing two-factor authentication (2FA) systems.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HOTPConfig ¶
type HOTPConfig struct { CodeLength int // CodeLength is the length of the generated OTP code. HashType HashType // HashType is the hash algorithm used for OTP generation. Secret []byte // Secret is the shared secret key used for OTP generation. Counter int // Counter is the initial counter value for HOTP generation. SynchronizationLimit int // SynchronizationLimit sets the limit for synchronization in HOTP validation. }
HOTPConfig holds configuration parameters for HOTP generation.
type HTOP ¶
type HTOP struct { Counter int // contains filtered or unexported fields }
HTOP represents a Sequence-based One-Time Password generator.
func NewHTOP ¶
func NewHTOP(config HOTPConfig) *HTOP
NewHTOP creates a new instance of hopt based on the provided HOTPConfig.
func (*HTOP) Generate ¶
Generate returns a string representing a HOTP code. generating a code increments the HOTP counter
func (*HTOP) URI ¶
URI generates the URI according to the Google Authenticator Key URI Format. See: https://github.com/google/google-authenticator/wiki/Key-Uri-Format
type OTP ¶
type OTP struct { HashType HashType // HashType is the type of hash algorithm used. CodeLength int // CodeLength is the length of the generated OTP code. // contains filtered or unexported fields }
OTP represents a One-Time Password generator.
func NewOTP ¶
NewOTP creates a new instance of OTP based on the provided configuration. The function will substitute default values for parameters as per the specification:
- codeLength defaults to 6.
- hashFunc will default to SHA1.
- A secret is required but length is not enforced. RFC recommends a shared secret of at least 128 bits.
type TOTP ¶
type TOTP struct { TimePeriod int // TimePeriod is the time period in seconds used for TOTP generation. // contains filtered or unexported fields }
TOTP represents a Time-based One-Time Password generator.
func NewTOTP ¶
func NewTOTP(config TOTPConfig) *TOTP
NewTOTP creates a new instance of TOTP based on the provided configuration.
func (*TOTP) GenerateAt ¶
GenerateAt generates a TOTP for the given Unix timestamp.
func (*TOTP) URI ¶
URI generates the URI for the TOTP according to the Google Authenticator Key URI Format. See: https://github.com/google/google-authenticator/wiki/Key-Uri-Format
type TOTPConfig ¶
type TOTPConfig struct { TimeInterval int // TimeInterval is the time interval in seconds for TOTP generation. CodeLength int // CodeLength is the length of the generated TOTP code. HashType HashType // HashType is the hash algorithm used for TOTP generation. Secret []byte // Secret is the shared secret key used for TOTP generation. }
TOTPConfig holds configuration parameters for TOTP generation.