Documentation
¶
Overview ¶
Package motp provides a thread-safe, generic in-memory OTP manager.
It supports customizable character sets, expiration windows, and automatic background purging of stale tokens.
Basic usage:
store := motp.NewMemoryOtp[MyData]() code, err := store.GenerateOTP(data)
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrCodeNotFound = errors.New("code not present")
Functions ¶
This section is empty.
Types ¶
type MemoryOtp ¶
type MemoryOtp[T any] interface { GenerateOTP(otp_data OtpData[T]) (code string, err error) CheckIsKeyPresent(key string) (is_present bool) CheckOTP(key, code string) (ret_otp OtpData[T], err error) DeleteOTP(key string) error }
func NewMemoryOtp ¶
NewMemoryOtp creates and initializes a new in-memory OTP manager.
By default, it is initialized with:
- Code length: 7 digits
- Alphabet: "0973546281" (numeric)
- Cleanup interval: 15 seconds
Custom configuration can be applied by passing functional options (confs). On creation, it automatically spins up a background goroutine to periodically purge expired OTPs from memory.
Returns a thread-safe implementation of the MemoryOtp interface.
type OtpConf ¶
type OtpConf[T any] func(*otp_manager[T])
func WithOTPAlphabet ¶
WithOTPAlphabet configures the set of characters used when generating OTP codes.
If not specified, the manager defaults to "0973546281".
func WithOTPCleanupTime ¶
WithOTPCleanupTime sets the interval at which the background purger runs to remove expired OTPs from memory.
If not specified, the manager defaults to cleaning up every 15 seconds.
func WithOTPLen ¶
WithOTPLen sets a custom length for generated OTP codes.
If not specified, the manager defaults to generating 7-character codes.