xlzd / gotp

Golang OTP(One-Time Password) Library.
MIT License
468 stars 67 forks source link

How to set step length for TOTP? #7

Closed jiftle closed 4 years ago

jiftle commented 4 years ago

TOTP algorithm has the param of control step length , but I don't found it. Please ...

// Generate the current time OTP and expiration time
func (t *TOTP) NowWithExpiration() (string, int64) {
    interval64 := int64(t.interval)
    timeCodeInt64 := time.Now().Unix() / interval64
    expirationTime := (timeCodeInt64 + 1) * interval64
    return t.generateOTP(int(timeCodeInt64)), expirationTime
}
mergenchik commented 4 years ago

@jiftle t.interval is step length.

You can use NewTOTP(secret string, digits, interval int, hasher *Hasher) *TOTP function, for other parameters refer to NewDefaultTOTP(secret string) for usage, both in totp.go file.

mergenchik commented 4 years ago

@jiftle can we close this issue now?