sec51 / twofactor

Golang two factor authentication library
ISC License
217 stars 66 forks source link

OTP Expiration time #29

Open Abdullah-khalid opened 2 years ago

Abdullah-khalid commented 2 years ago

Hi, great job with the library, is there any option to increse the expiration time of generated OTP?

uvulpos commented 2 years ago

https://github.com/sec51/twofactor/blob/master/totp.go#L109

func makeTOTP(key []byte, account, issuer string, hash crypto.Hash, digits int) (*Totp, error) {
    otp := new(Totp)
    otp.key = key
    otp.account = account
    otp.issuer = issuer
    otp.digits = digits
    otp.stepSize = 30 // we set it to 30 seconds which is the recommended value from the RFC
    otp.clientOffset = 0
    otp.hashFunction = hash
    return otp, nil
}

You call the NewTOTP Function, which calls and returns the makeTOTP Function. So, I would assume if you got the *TOTP back, you could just set the stepSize to something else. BUT I would not recommend you to do this, since the point of TOTP is that it is only valid for 30 seconds.

https://en.wikipedia.org/wiki/Time-based_one-time_password

hope that help