Browse Source

Use the totp period from Uri instead of hard coded value

Bubka 5 years ago
parent
commit
9fa4308e24
1 changed files with 6 additions and 3 deletions
  1. 6 3
      app/Classes/TimedTOTP.php

+ 6 - 3
app/Classes/TimedTOTP.php

@@ -26,11 +26,14 @@ class TimedTOTP
         }
         }
 
 
         $currentPosition = time();
         $currentPosition = time();
-        $PeriodCount = floor($currentPosition / 30); //nombre de période de 30s depuis T0
-        $currentPeriodStartAt = $PeriodCount * 30;
-        $currentPeriodendAt = $currentPeriodStartAt + 30;
+        $PeriodCount = floor($currentPosition / $otp->getPeriod()); //nombre de période de x s depuis T0 (x=30 par défaut)
+        $currentPeriodStartAt = $PeriodCount * $otp->getPeriod();
         $positionInCurrentPeriod = $currentPosition - $currentPeriodStartAt;
         $positionInCurrentPeriod = $currentPosition - $currentPeriodStartAt;
 
 
+        // for memo :
+        // $nextOtpAt = ($PeriodCount+1)*$period
+        // $remainingTime = $nextOtpAt - time()
+
         $totp = [
         $totp = [
             'totp' => $otp->now(),
             'totp' => $otp->now(),
             'position' => $positionInCurrentPeriod
             'position' => $positionInCurrentPeriod