From 806726d1095cf6dc64fc5fa02c800dff4e950d58 Mon Sep 17 00:00:00 2001 From: TheArrayser Date: Wed, 28 Jun 2023 16:43:53 +0200 Subject: [PATCH] Made code workable for old Java Versions --- .../cringe_authenticator_library/impl/TOTP.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/cringe_studios/cringe_authenticator_library/impl/TOTP.java b/src/main/java/com/cringe_studios/cringe_authenticator_library/impl/TOTP.java index e9623a3..96f6758 100644 --- a/src/main/java/com/cringe_studios/cringe_authenticator_library/impl/TOTP.java +++ b/src/main/java/com/cringe_studios/cringe_authenticator_library/impl/TOTP.java @@ -3,7 +3,6 @@ package com.cringe_studios.cringe_authenticator_library.impl; import java.nio.ByteBuffer; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; -import java.time.Instant; import com.cringe_studios.cringe_authenticator_library.OTPAlgorithm; import com.cringe_studios.cringe_authenticator_library.OTPException; @@ -27,7 +26,7 @@ public class TOTP extends HOTP { @Override public String getPin() throws OTPException{ try { - return getPinAt(Instant.now().getEpochSecond()); + return getPinAt(System.currentTimeMillis() / 1000); } catch (InvalidKeyException e) { throw new OTPException("Your secret is invalid! Please rescan the code!", e); } catch (NoSuchAlgorithmException e) { @@ -37,7 +36,7 @@ public class TOTP extends HOTP { @Override public long getCounter() { - return getCounterAt(Instant.now().getEpochSecond() - super.getTimeCorrection()); + return getCounterAt(System.currentTimeMillis() / 1000 - super.getTimeCorrection()); } private long getCounterAt(long unixSecond) {