README
¶
gototp
Go Time-Based One Time Password implemention of RFC6238 (http://tools.ietf.org/html/rfc6238)
Based on pyotp: https://github.com/nathforge/pyotp
USAGE
gototp is easy to use:
- Generate a random secret to store for a user:
// Do this somewhere early, and only once
rnd := rand.New(rand.NewSource(time.Now().Unix())
// A secret length of 10 gives a 16 character secret key
secret := gototp.RandomSecret(10, rand.New(rand.NewSource(time.Now().Unix())))
- Create the OTP object:
// Create the OTP
otp, err := gototp.New(secret)
if nil!=err {
panic(err)
}
- Find the current TOTP code:
code := otp.Now()
// Or find the previous code and the next code
previousCode := otp.FromNow(-1)
nextCode := otp.FromNow(1)
- Generate a Google Charts URL for a QR Code of the Secret, with a label
// Google Charts URL to display a QR Code, of width (and height) 300px
url := otp.QRCodeGoogleChartsUrl("My Own TOTP", 300)
Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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).