DecryptActivity: properly calculate remaining OTP time on first pass (#1080)

* DecryptActivity: properly calculate remaining OTP time on first pass

We default to 30 seconds for each recalculation but the first run might not have 30 seconds left in its period, making the value stale much earlier. While most websites offer another 30 seconds of validity for TOTP codes, many do not, thus making it hard to enter a correct OTP

Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>

* Update changelog

Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
Harsh Shandilya 2020-09-05 20:12:19 +05:30 committed by GitHub
parent 0b85779eec
commit 6713d48974
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 0 deletions

View file

@ -24,6 +24,7 @@ All notable changes to this project will be documented in this file.
- Git server protocol and authentication mode are only updated when explicitly saved
- Remember HTTPS password during a sync operation
- Unable to use show/hide password option for password/passphrase after first attempt was wrong
- TOTP values shown might some times be stale and considered invalid by sites
## [1.11.3] - 2020-08-27

View file

@ -194,6 +194,13 @@ class DecryptActivity : BasePgpActivity(), OpenPgpServiceConnection.OnBound {
)
}
launch(Dispatchers.IO) {
// Calculate the actual remaining time for the first pass
// then return to the standard 30 second affair.
val remainingTime = entry.totpPeriod - (System.currentTimeMillis() % entry.totpPeriod)
withContext(Dispatchers.Main) {
otpText.setText(entry.calculateTotpCode() ?: "Error")
}
delay(remainingTime.seconds)
repeat(Int.MAX_VALUE) {
val code = entry.calculateTotpCode() ?: "Error"
withContext(Dispatchers.Main) {