Documentation ¶
Index ¶
- func RandomSecret(length int) string
- type TOTP
- func (totp *TOTP) ForPeriod(period int64) int32
- func (totp *TOTP) FromNow(periods int64) int32
- func (totp *TOTP) Now() int32
- func (totp *TOTP) QRCodeData(label string) string
- func (totp *TOTP) QRCodeGoogleChartsUrl(label string, width int) string
- func (totp *TOTP) QRCodeTerminal(label string) (string, error)
- func (totp *TOTP) Secret() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RandomSecret ¶
Generate a Random secret encoded as a b32 string If the length is <= 0, a default length of 10 bytes will be used, which will generate a secret of length 16.
Types ¶
type TOTP ¶
type TOTP struct { Digits int // Number of digits for code. Defaults to 6. Period int // Number of seconds for each code. Defaults to 30. // contains filtered or unexported fields }
Time-based One Time Password
func (*TOTP) FromNow ¶
Return the Time Based One Time Password for the time-period that is Now + the given periods. This is useful if you want to provide some flexibility around the acceptance of codes. For instance, you might want to accept a code that is valid in the current period (FromNow(0)), or that was valid in the previous period (FromNow(-1)) or that will be valid in the next period (FromNow(1)). This means that every code is therefore valid for 3 * totp.Period.
func (*TOTP) QRCodeData ¶
Return the data to be contained in a QR Code for this TOTP with the given label.
func (*TOTP) QRCodeGoogleChartsUrl ¶
Return a URL to generate a QRCode on Google Charts for the TOTP, with the given label and width (and height equal to width).
func (*TOTP) QRCodeTerminal ¶
Returns a QR code for the TOTP The QR code has a very high error correction level