albertusdev / hotp-totp-generator

A HMAC-based OTP (HOTP) and Time-based OTP (TOTP) that generates OTP tokens from OTP key with customizable hash algorithm.
MIT License
15 stars 6 forks source link

Number of digits not followed #3

Closed maplepam closed 1 year ago

maplepam commented 4 years ago

The result of the algorithm returns either 9 or 10 digits only and does not follow the default number of digits (6) or any customized input.

The algorithm lacks the following step:

result = result % parseInt(Math.pow(10, parseFloat(digits)))

after the following line:

result = result & 0x7fffffff;

in truncate method

(implementation based on https://github.com/lachlanbell/SwiftOTP/blob/master/SwiftOTP/Generator.swift)