func (totp *TOTP) Generate() (code string, seconds int, err error) {
	var T0 int64 = 0 // initial counter time / start time
	var currentUnixTime int64

	if totp.Secret == "" {
		return "", 0, errors.New("TOTP secret key required")
	}

	if totp.Digits == 0 {
		totp.Digits = 6
	}

	if totp.Algorithm == "" {
		totp.Algorithm = "SHA1"
	}

	if totp.Period == 0 {
		totp.Period = 30
	}

	if totp.UnixTime != 0 {
		currentUnixTime = totp.UnixTime // get OTP at the given timestamp
	} else {
		currentUnixTime = time.Now().Unix() - T0 // get OTP at current timestamp
	}

	counter := currentUnixTime / totp.Period
	code, err = generateOTP(totp.Secret, counter, totp.Digits, totp.Algorithm)
	seconds = int(totp.Period - currentUnixTime%totp.Period)
	return
}
// Generates TOTP code and returns OTP as string, seconds remaining and any error encountered.
Generates TOTP code and returns OTP as string, seconds remaining and any error encountered.
// Generates TOTP code and returns OTP as string seconds remaining and any error encountered .
func (totp *TOTP) Generate() (code string, seconds int, err error) {
	var T0 int64 = 0 
	var currentUnixTime int64
	if totp.Secret == "" {
		return "", 0, errors.New("TOTP secret key required")
	}
	if totp.Digits == 0 {
		totp.Digits = 6
	}
	if totp.Algorithm == "" {
		totp.Algorithm = "SHA1"
	}
	if totp.Period == 0 {
		totp.Period = 30
	}
	if totp.UnixTime != 0 {
		currentUnixTime = totp.UnixTime 
	} else {
		currentUnixTime = time.Now().Unix() - T0 
	}
	counter := currentUnixTime / totp.Period
	code, err = generateOTP(totp.Secret, counter, totp.Digits, totp.Algorithm)
	seconds = int(totp.Period - currentUnixTime%totp.Period)
	return
}
func ( totp * TOTP ) Generate ( ) ( code string , seconds int , err error ) { var T0 int64 = 0 var currentUnixTime int64 if totp . Secret == " " { return " " , 0 , errors . New ( " " ) } if totp . Digits == 0 { totp . Digits = 6 } if totp . Algorithm == " " { totp . Algorithm = " " } if totp . Period == 0 { totp . Period = 30 } if totp . UnixTime != 0 { currentUnixTime = totp . UnixTime } else { currentUnixTime = time . Now ( ) . Unix ( ) - T0 } counter := currentUnixTime / totp . Period code , err = generateOTP ( totp . Secret , counter , totp . Digits , totp . Algorithm ) seconds = int ( totp . Period - currentUnixTime % totp . Period ) return }
Generates TOTP code and returns OTP as string, seconds remaining and any error encountered.
Generates TOTP code and returns OTP as string seconds remaining and any error encountered .
// initial counter time / start time // get OTP at the given timestamp // get OTP at current timestamp