From a627b889af3173ffda29b0cf32ed7802e8090a15 Mon Sep 17 00:00:00 2001 From: William Hall Date: Fri, 19 Mar 2021 17:05:13 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9A=20clean=20up=20demo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- demo/demo.php | 54 ++++++++++++++++++++++++++++++++----------------- demo/loader.php | 50 --------------------------------------------- 2 files changed, 35 insertions(+), 69 deletions(-) delete mode 100644 demo/loader.php diff --git a/demo/demo.php b/demo/demo.php index 996dd92..9139381 100644 --- a/demo/demo.php +++ b/demo/demo.php @@ -6,30 +6,46 @@
    First create a secret and associate it with a user'; - $secret = $tfa->createSecret(160); // Though the default is an 80 bits secret (for backwards compatibility reasons) we recommend creating 160+ bits secrets (see RFC 4226 - Algorithm Requirements) - echo '
  1. Next create a QR code and let the user scan it:

    ...or display the secret to the user for manual entry: ' . chunk_split($secret, 4, ' '); - $code = $tfa->getCode($secret); - echo '
  2. Next, have the user verify the code; at this time the code displayed by a 2FA-app would be: ' . $code . ' (but that changes periodically)'; - echo '
  3. When the code checks out, 2FA can be / is enabled; store (encrypted?) secret with user and have the user verify a code each time a new session is started.'; - echo '
  4. When aforementioned code (' . $code . ') was entered, the result would be: ' . (($tfa->verifyCode($secret, $code) === true) ? 'OK' : 'FAIL'); + // substitute your company or app name here + $tfa = new RobThree\Auth\TwoFactorAuth('RobThree TwoFactorAuth'); ?> +
  5. First create a secret and associate it with a user
  6. + createSecret(); + ?> +
  7. + Next create a QR code and let the user scan it:
    +
    + ...or display the secret to the user for manual entry: + +
  8. + getCode($secret); + ?> +
  9. Next, have the user verify the code; at this time the code displayed by a 2FA-app would be: (but that changes periodically)
  10. +
  11. When the code checks out, 2FA can be / is enabled; store (encrypted?) secret with user and have the user verify a code each time a new session is started.
  12. +
  13. + When aforementioned code () was entered, the result would be: + verifyCode($secret, $code) === true) { ?> + OK + + FAIL + +

Note: Make sure your server-time is NTP-synced! Depending on the $discrepancy allowed your time cannot drift too much from the users' time!

ensureCorrectTime(); - echo 'Your hosts time seems to be correct / within margin'; - } catch (RobThree\Auth\TwoFactorAuthException $ex) { - echo 'Warning: Your hosts time seems to be off: ' . $ex->getMessage(); - } + try { + $tfa->ensureCorrectTime(); + echo 'Your hosts time seems to be correct / within margin'; + } catch (RobThree\Auth\TwoFactorAuthException $ex) { + echo 'Warning: Your hosts time seems to be off: ' . $ex->getMessage(); + } ?> diff --git a/demo/loader.php b/demo/loader.php deleted file mode 100644 index 208f24d..0000000 --- a/demo/loader.php +++ /dev/null @@ -1,50 +0,0 @@ -=0;$i--) { - static::$parentPath = dirname(static::$parentPath); - } - static::$paths = array(); - static::$files = array(__FILE__); - } - - public static function register($path,$namespace) { - if (!static::$initialized) static::initialize(); - static::$paths[$namespace] = trim($path,DIRECTORY_SEPARATOR); - } - - public static function load($class) { - if (class_exists($class,false)) return; - if (!static::$initialized) static::initialize(); - - foreach (static::$paths as $namespace => $path) { - if (!$namespace || $namespace.static::$nsChar === substr($class, 0, strlen($namespace.static::$nsChar))) { - - $fileName = substr($class,strlen($namespace.static::$nsChar)-1); - $fileName = str_replace(static::$nsChar, DIRECTORY_SEPARATOR, ltrim($fileName,static::$nsChar)); - $fileName = static::$parentPath.DIRECTORY_SEPARATOR.$path.DIRECTORY_SEPARATOR.$fileName.'.php'; - - if (file_exists($fileName)) { - include $fileName; - return true; - } - } - } - return false; - } -} - -spl_autoload_register(array('Loader', 'load')); \ No newline at end of file