hectorm/otpauth

Time sync token

mazkaaa opened this issue · 3 comments

Hello,
I'm currently developing a 2fa authenticator application based on the web platform. May I know how to utilize time synchronization with the token generated by the library?

Here is the application developed by myself: Otentikator

Thank you!

Hi, I'm not quite sure what you want to do, could you be more specific?

In the case of TOTP it defaults to the Date.now method for the timestamp:
https://github.com/hectorm/otpauth/blob/v7.1.3/src/totp.js#L113

Hi, I'm not quite sure what you want to do, could you be more specific?

In the case of TOTP it defaults to the Date.now method for the timestamp: https://github.com/hectorm/otpauth/blob/v7.1.3/src/totp.js#L113

ohh hmm I'd like to know how long the token will be active until the period's time runs out? for example, I set the period duration on 30second. but how do I know the total duration left on the generated token?

You can use this formula to calculate the seconds remaining: 30 * (1 - ((Date.now() / 1000) / 30 % 1)) | 0