xlzd / gotp

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

unable to generate OTP with more than 9 digits #4

Closed jproig closed 4 years ago

jproig commented 5 years ago

Hi, I tried to generate and OTP fo 10 digits (I understand that OTPs of more thatn 6-8 digits are really unusual) but the generateOTP() is capping it to 9 digits. I think the problem is since line 51 (otp.go) clamps to 31b and 1<<31 < 1e10, this can't be more than 9. I am ok with 9 being a limit, but that should probably be clearly documented and/or asserted somewhere. Thanks

jproig commented 5 years ago

This is how I tested it: https://play.golang.org/p/5aYxVctNs3w

mergenchik commented 4 years ago

Since int is used inside, which is 32 bit signed integer and maximum is 2147483647, and also because of clamping which you noticed OTP more than 9 digit is not possible.

mergenchik commented 4 years ago

I am closing this issue