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

"java.lang.ArithmeticException: / by zero" AllowedTimePeriodDiscrepancy can not be zero #61

Open
alessandroAmedei opened this issue Oct 23, 2024 · 0 comments

Comments

@alessandroAmedei
Copy link

I would like a code to be valid only for 30 second in its period:

        int MFA_PERIOD = 30;
        int MFA_ALLOWED_TIME_PERIOD_DISCREPANCY = 0;
        DefaultCodeVerifier verifier = new DefaultCodeVerifier(codeGenerator, timeProvider);
        verifier.setTimePeriod(MFA_PERIOD );
        verifier.setAllowedTimePeriodDiscrepancy(MFA_ALLOWED_TIME_PERIOD_DISCREPANCY);

But when i call the method "isValidCode" i get:

java.lang.ArithmeticException: / by zero
	at java.base/java.lang.Math.floorDiv(Math.java:1288)
	at dev.samstevens.totp.code.DefaultCodeVerifier.isValidCode(DefaultCodeVerifier.java:30)

I can get the same result doing:

MFA_PERIOD = 15;
MFA_ALLOWED_TIME_PERIOD_DISCREPANCY = 1;

        t|--------------|-----15sec----|
            ^generating otp xyz
        t|-----------------------------|
         xyz is valid for 30 secondi

But is this the correct solution?

@alessandroAmedei alessandroAmedei changed the title AllowedTimePeriodDiscrepancy can not be zero "java.lang.ArithmeticException: / by zero" AllowedTimePeriodDiscrepancy can not be zero Oct 23, 2024
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