Skip to content

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

@alessandroAmedei

Description

@alessandroAmedei

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions