Documentation ¶
Overview ¶
Package totp contains an RFC6238 implementation of time-based one time passwords.
To be able to generate codes, you need to create a TOTP object using a secret:
import ( "gopkg.in/zhevron/go-twofactor.v1" "gopkg.in/zhevron/go-twofactor.v1/totp" ) secret := twofactor.NewSecret(0) otp := totp.NewTOTP(secret, 0, 0)
After creating the TOTP object, you can easily generate the current code by calling the Code method:
code, err := otp.Code() if err != nil { // Failed to generate the code }
A convenience method is also provided for checking if a code is valid using time period offset:
code := 123456 if otp.Validate(code, 0) { // Code is valid } else { // Code is not valid }
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type TOTP ¶
type TOTP struct {
// contains filtered or unexported fields
}
TOTP implements time-based one time passwords as specified in RFC6238 (http://tools.ietf.org/html/rfc6238).
func NewTOTP ¶
NewTOTP makes a new TOTP object for generating OTP codes from a given Secret. If length is 0 or less, it will default to a length of 6. If duration is 0 or less, it will default to a duration of 30 seconds.
func (TOTP) ForPeriodOffset ¶
ForPeriodOffset returns the code from the time period of current+offset.