GoogleAuth icon indicating copy to clipboard operation
GoogleAuth copied to clipboard

Generate a code which will be valid for the next 30 seconds

Open slimeball1234 opened this issue 5 years ago • 1 comments

Hello,

I am trying to use your library to generate a code which will be valid for the next 60s. The code I am using is:

GoogleAuthenticatorConfigBuilder gacb = new GoogleAuthenticatorConfigBuilder() .setWindowSize(2);

GoogleAuthenticator googleAuthenticator = new GoogleAuthenticator(gacb.build()); GoogleAuthenticatorKey googleAuthenticatorKey = googleAuthenticator.createCredentials();

String secretKey = googleAuthenticatorKey.getKey();

int code = googleAuthenticator.getTotpPassword(secretKey);

try { Thread.sleep(30000); } catch (InterruptedException ex) { Logger.getLogger(MainGoogleAuthenticator.class.getName()).log(Level.SEVERE, null, ex); }

googleAuthenticator.authorize(secretKey, code);

The code is sometimes valid, sometimes it is not. I would assume that with the default window time frame of 30 seconds, and the window size of 2, which together makes 60 s, that the generated code above will always be valid as the thread.sleep lasts only 30 s. What am I doing wrong?

Thank you, Ivan

slimeball1234 avatar Sep 07 '20 08:09 slimeball1234

Hey, I have same issue, it worked for me for some time, but then it started bugging and the code is sometimes valid, and valid it becomes when you have like 5-10 seconds before end.

Jakush avatar Sep 22 '23 19:09 Jakush