Use correct time to find TOTP secret (#1387)

This commit is contained in:
Aditya Wasan 2021-04-18 15:38:54 +05:30 committed by GitHub
parent 7710ca9024
commit 7a532302e3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -14,6 +14,7 @@ import dev.msfjarvis.aps.util.totp.Otp
import dev.msfjarvis.aps.util.totp.TotpFinder import dev.msfjarvis.aps.util.totp.TotpFinder
import kotlin.collections.set import kotlin.collections.set
import kotlin.time.ExperimentalTime import kotlin.time.ExperimentalTime
import kotlin.time.seconds
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.MutableStateFlow
@ -83,10 +84,10 @@ constructor(
scope.launch { scope.launch {
updateTotp(clock.millis()) updateTotp(clock.millis())
val remainingTime = totpPeriod - (System.currentTimeMillis() % totpPeriod) val remainingTime = totpPeriod - (System.currentTimeMillis() % totpPeriod)
delay(remainingTime) delay(remainingTime.seconds)
repeat(Int.MAX_VALUE) { repeat(Int.MAX_VALUE) {
updateTotp(clock.millis()) updateTotp(clock.millis())
delay(totpPeriod) delay(totpPeriod.seconds)
} }
} }
} }