Move delay to between getting verification result, and checking the result.

Piotr Pawlow [2017-03-19 17:20:56]
Move delay to between getting verification result, and checking the result.
Filename
auth.php
diff --git a/auth.php b/auth.php
index 7e839c9..ccb2859 100644
--- a/auth.php
+++ b/auth.php
@@ -23,14 +23,15 @@ foreach($config_default as $k => $v) if (!isset($config->{$k})) $config->{$k} =
 if (!preg_match('/^[A-Z2-7]+$/i', $config->secret)) die("Base32 encoded secret required\n");
 $totp = new TOTP(null, $config->secret, $config->period, $config->digest, $config->digits);
 while(true) {
-  sleep($config->delay);
   echo "Czas serwera: ";
   $now = new DateTime();
   echo $now->format('Y-m-d H:i:s');
   echo "\n";
   echo "Podaj kod:\n";
   $code = readline();
-  if ($totp->verify($code, null, $config->window)) {
+  $verify_result = $totp->verify($code, null, $config->window);
+  sleep($config->delay);
+  if ($verify_result) {
     break;
   } else {
     echo "Zły kod\n";
ViewGit