wstrange / GoogleAuth

Google Authenticator Server side code

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Setting timeout to passcode

AjayPara opened this issue · comments

How can we restrict the passcode's lifetime?
I am trying it by using the setTimeStepSizeInMillis method but it doesn't seem to be working.
Can anyone help me with this?

commented

Try this

// config builder
GoogleAuthenticatorConfig.GoogleAuthenticatorConfigBuilder builder = new GoogleAuthenticatorConfig.GoogleAuthenticatorConfigBuilder()
                .setCodeDigits(8)
                .setTimeStepSizeInMillis(TimeUnit.SECONDS.toMillis(60L))
                .setSecretBits(80);
        
// config
GoogleAuthenticatorConfig config = builder.build();
        
// google authenticator
GoogleAuthenticator googleAuthenticator = new GoogleAuthenticator(config);

Yes, the 'lifetime' of a passcode is called step size in the TOTP RFC.