Made code workable for old Java Versions

This commit is contained in:
TheArrayser 2023-06-28 16:43:53 +02:00
parent 291ecd6c7a
commit 806726d109

View File

@ -3,7 +3,6 @@ package com.cringe_studios.cringe_authenticator_library.impl;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.security.InvalidKeyException; import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.time.Instant;
import com.cringe_studios.cringe_authenticator_library.OTPAlgorithm; import com.cringe_studios.cringe_authenticator_library.OTPAlgorithm;
import com.cringe_studios.cringe_authenticator_library.OTPException; import com.cringe_studios.cringe_authenticator_library.OTPException;
@ -27,7 +26,7 @@ public class TOTP extends HOTP {
@Override @Override
public String getPin() throws OTPException{ public String getPin() throws OTPException{
try { try {
return getPinAt(Instant.now().getEpochSecond()); return getPinAt(System.currentTimeMillis() / 1000);
} catch (InvalidKeyException e) { } catch (InvalidKeyException e) {
throw new OTPException("Your secret is invalid! Please rescan the code!", e); throw new OTPException("Your secret is invalid! Please rescan the code!", e);
} catch (NoSuchAlgorithmException e) { } catch (NoSuchAlgorithmException e) {
@ -37,7 +36,7 @@ public class TOTP extends HOTP {
@Override @Override
public long getCounter() { public long getCounter() {
return getCounterAt(Instant.now().getEpochSecond() - super.getTimeCorrection()); return getCounterAt(System.currentTimeMillis() / 1000 - super.getTimeCorrection());
} }
private long getCounterAt(long unixSecond) { private long getCounterAt(long unixSecond) {