otp

package
v0.0.0-...-012890b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 10, 2022 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Itob

func Itob[T int | int64](value T) []byte

Converts integer to byte array

Types

type OTP

type OTP struct {
	Secret   string
	Digits   int
	TimeStep int
	HashName string
	Encoding string
}

func NewOtp

func NewOtp(p OTP) (OTP, error)

* The init function must be provided with an OTP struct * The secret string must be always provided and it can be encoded in any of base32, base64, hex or utf-8; * if the string encoding differs from base32 you must provide the encoding parameter too * * The variables of the OTP struct are optional other than Secret are optional: * Digits: the lengh of the otp string (values admitted 5 - 10; default: 6) * TimeStep: the time step for totp code duration (values admitted any positive value; default: 30) * HashName: the name of the hashing function (values admitted sha1, sha256, sha512; default: sha1) * Encoding: the encoding of the secret string (values admitted base32, base64, hex, utf-8; default: base32)

func (*OTP) GenerateHmacOtp

func (otp *OTP) GenerateHmacOtp(counter int64) string

* Generates a HMAC based one time password based on a counter * * The counter value must be provided as function parameter which is not auto incremented

func (*OTP) GenerateSteamguardCode

func (otp *OTP) GenerateSteamguardCode() string

* Generates the steamguard version of the time-based one time password * every time_step interval using the current unix timestamp as timecode; * use this if alphanumeric code is needed * * To use this the digits parameter must be set to 5

func (*OTP) GenerateSteamguardCodeAt

func (otp *OTP) GenerateSteamguardCodeAt(timestamp int64) string

* Generates the steamguard version of the time-based one time password * every time_step interval using the unix timestamp specified in function parameter * as timecode; use this if alphanumeric code is needed * * To use this the digits parameter must be set to 5

func (*OTP) GenerateTotpAt

func (otp *OTP) GenerateTotpAt(timestamp int64) string

* Generates a time-based one time password every time_step interval * using the unix timestamp specified in function parameter

func (*OTP) GenerateTotpNow

func (otp *OTP) GenerateTotpNow() string

* Generates a time-based one time password every time_step interval * using the current unix timestamp as timecode

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL