Documentation ¶
Index ¶
- func BuildURI(otpType OTPType, secret, accountName, issuerName, algorithm string, ...) string
- func CheckRfc4226TOTPKey(n int, otp, secret string) bool
- func CheckRfc6238TOTPKey(un, otp, secret string) bool
- func CheckRfc6238TOTPKeyWithSkew(un, otp, secret string, skew, pskew uint) bool
- func CurrentTimestamp() int
- func ExtractURIFromQRCodeImage(fn string) (uri string, err error)
- func GenerateQRCodeFromURI(uri, fn string)
- func GenerateRfc4226HOTPKey(n int, secret string) (string, error)
- func GenerateRfc6238TOTPKey(un, secret string) string
- func GenerateRfc6238TOTPKeyTL(un, secret string) (pin2fa string, tl uint)
- func PadRight(str, pad string, lenght int) string
- func RandomSecret(length int) string
- type HOTP
- type Hasher
- type OTP
- type OTPType
- type TOTP
- func (tt *TOTP) At(timestamp int) string
- func (tt *TOTP) AtTL(timestamp int) (pin2fa string, tr uint)
- func (tt *TOTP) GenerateTOTPAndSecondsLeft() (otp string, timeLeft int)
- func (tt TOTP) GetTimeWindow() int
- func (tt *TOTP) Now() string
- func (tt *TOTP) ProvisioningUri(un, realm string) string
- func (tt *TOTP) SetSkew(skew, pskew uint)
- func (tt *TOTP) Verify(otp string) bool
- func (tt *TOTP) VerifyAtTimestamp(otp string, timestamp int) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildURI ¶
func BuildURI(otpType OTPType, secret, accountName, issuerName, algorithm string, startCount, digits, period int) string
BuildURI returns the provisioning URI for the OTP. This works for both TOTP or HOTP. The URI is suitable for encoding in a QR-Code that can then be read by Google Authenticator or the command line ./tools/ac with the --import flag. The ./tools/ac can use the --importURI to import the string URI instead of parsing a QR code image.
See also:
https://github.com/google/google-authenticator/wiki/Key-Uri-Format
Parameters:
otpType: OTP type, must be one of { "totp", "hotp" } secret: The secret used to generate the URI accountName: Username - used on server to retretive the secret. issuerName: Name of the OTP issuer. This is the title of the OTP entry in Google Authenticator. algorithm: The algorithm used in the OTP generation, defauilt is "sha1" but other hashes can be used. startCount: For HOTP the starting counter value. Ignored in TOTP. digits: The number of digits in the generated OTP. Default 6. Pass 0 for the default. period: The number of seconds before the OTP expires. Default 30. Pass 0 for the default.
Returns: the provisioning URI
func CheckRfc4226TOTPKey ¶ added in v0.4.3
func CheckRfc6238TOTPKey ¶ added in v0.1.1
CheckRfc6238TOTPKey uses the `otp` and `secret` to check that the `otp` is valid.
func CheckRfc6238TOTPKeyWithSkew ¶ added in v0.1.1
func CurrentTimestamp ¶
func CurrentTimestamp() int
CurrentTimestamp will return the current Unix timestamp.
func ExtractURIFromQRCodeImage ¶
Extract URI from QR Code Image
func GenerateQRCodeFromURI ¶
func GenerateQRCodeFromURI(uri, fn string)
Generate QR Code Image from URI
func GenerateRfc4226HOTPKey ¶ added in v0.4.3
func GenerateRfc6238TOTPKey ¶ added in v0.1.1
func GenerateRfc6238TOTPKeyTL ¶ added in v0.1.2
func RandomSecret ¶
RandomSecret will generate a random secret of given length in a suitable format for use in either HOTP or TOTP.
Types ¶
type HOTP ¶
type HOTP struct {
OTP
}
func NewDefaultHOTP ¶
func (*HOTP) ProvisioningUri ¶
ProvisioningUri returns the provisioning URI for the OTP. This can then be encoded in a QR Code and used to provision an OTP app like Google Authenticator.
See also: https://github.com/google/google-authenticator/wiki/Key-Uri-Format
Parameters:
un Username - used on the server to lookup the secret. realm Name of the issuer of the OTP cnt Initial Count to start with
type Hasher ¶
From Copyright (c) 2018 xlzd, https://github.com/xlzd/gotp, MIT Licensed.
type OTP ¶
type OTP struct {
// contains filtered or unexported fields
}
From Copyright (c) 2018 xlzd, https://github.com/xlzd/gotp, MIT Licensed.
func NewOTP ¶
From Copyright (c) 2018 xlzd, https://github.com/xlzd/gotp, MIT Licensed.
func (*OTP) ConvertSecretToBytes ¶
From Copyright (c) 2018 xlzd, https://github.com/xlzd/gotp, MIT Licensed.
type TOTP ¶
type TOTP struct { OTP // contains filtered or unexported fields }
time-based OTP, TOTP - uses the counter as a time window.
func NewDefaultTOTP ¶
NewDefaultTOTP returns a TOTP with default setup. 6 digits and a time window of 30 seconds. The hashis the default hashing algorythm.
func (*TOTP) GenerateTOTPAndSecondsLeft ¶
GenerateTOTPAndSecondsLeft Generate the current time OTP and number of seconds left in window. This is useful for a count-down display of how long the OTP is valid.
func (TOTP) GetTimeWindow ¶
func (*TOTP) ProvisioningUri ¶
ProvisioningUri returns the provisioning URI for the OTP. This can then be encoded in a QR Code and used to provision an OTP app like Google Authenticator.
See also: https://github.com/google/google-authenticator/wiki/Key-Uri-Format
Parameters:
un Username - used on the server to lookup the secret. realm Name of the issuer of the OTP