gotp: github.com/xlzd/gotp Index | Files | Directories

package gotp

import "github.com/xlzd/gotp"

Index

Package Files

doc.go hotp.go otp.go totp.go utils.go

Constants

const (
    OtpTypeTotp = "totp"
    OtpTypeHotp = "hotp"
)

func BuildUri Uses

func BuildUri(otpType, secret, accountName, issuerName, algorithm string, initialCount, digits, period int) string

Returns the provisioning URI for the OTP; works for either TOTP or HOTP. This can then be encoded in a QR Code and used to provision the Google Authenticator app. For module-internal use. See also:

https://github.com/google/google-authenticator/wiki/Key-Uri-Format

params:

otpType:     otp type, must in totp/hotp
secret:       the hotp/totp secret used to generate the URI
accountName:  name of the account
issuerName:   the name of the OTP issuer; this will be the organization title of the OTP entry in Authenticator
algorithm:    the algorithm used in the OTP generation
initialCount: starting counter value. Only works for hotp
digits:       the length of the OTP generated code.
period:       the number of seconds the OTP generator is set to expire every code.

returns: provisioning uri

func Itob Uses

func Itob(integer int) []byte

integer to byte array

func RandomSecret Uses

func RandomSecret(length int) string

generate a random secret of given length

type HOTP Uses

type HOTP struct {
    OTP
}

HMAC-based OTP counters.

func NewDefaultHOTP Uses

func NewDefaultHOTP(secret string) *HOTP

func NewHOTP Uses

func NewHOTP(secret string, digits int, hasher *Hasher) *HOTP

func (*HOTP) At Uses

func (h *HOTP) At(count int) string

Generates the OTP for the given count.

func (*HOTP) ProvisioningUri Uses

func (h *HOTP) ProvisioningUri(accountName, issuerName string, initialCount int) string

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

params:

accountName:  name of the account
issuerName:   the name of the OTP issuer; this will be the organization title of the OTP entry in Authenticator
initialCount: starting HMAC counter value

returns: provisioning URI

func (*HOTP) Verify Uses

func (h *HOTP) Verify(otp string, count int) bool

Verify OTP.

params:

otp:   the OTP to check against
count: the OTP HMAC counter

type Hasher Uses

type Hasher struct {
    HashName string
    Digest   func() hash.Hash
}

type OTP Uses

type OTP struct {
    // contains filtered or unexported fields
}

func NewOTP Uses

func NewOTP(secret string, digits int, hasher *Hasher) OTP

type TOTP Uses

type TOTP struct {
    OTP
    // contains filtered or unexported fields
}

time-based OTP counters.

func NewDefaultTOTP Uses

func NewDefaultTOTP(secret string) *TOTP

func NewTOTP Uses

func NewTOTP(secret string, digits, interval int, hasher *Hasher) *TOTP

func (*TOTP) At Uses

func (t *TOTP) At(timestamp int) string

Generate time OTP of given timestamp

func (*TOTP) Now Uses

func (t *TOTP) Now() string

Generate the current time OTP

func (*TOTP) NowWithExpiration Uses

func (t *TOTP) NowWithExpiration() (string, int64)

Generate the current time OTP and expiration time

func (*TOTP) ProvisioningUri Uses

func (t *TOTP) ProvisioningUri(accountName, issuerName string) string

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

params:

accountName: name of the account
issuerName:  the name of the OTP issuer; this will be the organization title of the OTP entry in Authenticator

returns: provisioning URI

func (*TOTP) Verify Uses

func (t *TOTP) Verify(otp string, timestamp int) bool

Verify OTP.

params:

otp:         the OTP to check against
timestamp:   time to check OTP at

Directories

PathSynopsis
example

Package gotp imports 10 packages (graph) and is imported by 8 packages. Updated 2018-10-30. Refresh now. Tools for package owners.