Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get time remaining #81

Open
joshstrange opened this issue Jun 26, 2019 · 1 comment
Open

Get time remaining #81

joshstrange opened this issue Jun 26, 2019 · 1 comment

Comments

@joshstrange
Copy link

I'm going to look to see if there is another way to calculate this (I'm sure there is) but it would be nice if there was a public method on GoogleAuthenticator to return the time that a pin generated would be valid for.

Like I said I'm sure I can do some math but I'm using this as a client and I would like to be able to display a countdown to the user. Yes I know the window size means the number will be larger but I also want to show the new code as soon as it becomes valid.

@joshstrange
Copy link
Author

It looks like this should be as simple as:

120 - (Math.round((new GregorianCalendar()).getTimeInMillis() / 1000) % 120)

Where 120 is the second you make it valid:

.setTimeStepSizeInMillis(TimeUnit.SECONDS.toMillis(120))

Of course your window size will probably make it valid for LONGER but for the purposes of UI this gives me an accurate countdown. In the end since this is for a web app I'll probably just do the calculation in javascript on the front end:

console.log(120 - Math.round(new Date() / 1000) % 120)

Yes, the web front end is acting like a TOTP generator for another device, I know it sounds weird but trust me, it's what I want for the project I'm working on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant