From 9170b8e981775425fdc983c78da3eebebeb36e86 Mon Sep 17 00:00:00 2001 From: Filippo Tessarotto Date: Wed, 19 Oct 2022 10:37:38 +0200 Subject: [PATCH] Update doc as well --- doc/AppConfig.md | 12 +++++------- doc/Customize.md | 46 ++++++++++++++++++++-------------------------- doc/QA.md | 10 ++++------ 3 files changed, 29 insertions(+), 39 deletions(-) diff --git a/doc/AppConfig.md b/doc/AppConfig.md index 5f2a4ef..486cd52 100644 --- a/doc/AppConfig.md +++ b/doc/AppConfig.md @@ -92,13 +92,11 @@ Now run the following and compare the output setLabel('alice@google.com'); // The label (string) +$totp = TOTP::createFromSecret('JBSWY3DPEHPK3PXP'); // New TOTP with custom secret +$totp->setPeriod(10); // The period (int) +$totp->setDigest('sha512'); // The digest algorithm (string) +$totp->setDigits(8); // The number of digits (int) +$totp->setLabel('alice@google.com'); // The label (string) echo 'Current OTP: ' . $totp->now(); ``` diff --git a/doc/Customize.md b/doc/Customize.md index db57894..4796420 100644 --- a/doc/Customize.md +++ b/doc/Customize.md @@ -35,13 +35,11 @@ By default, the period for a TOTP is 30 seconds and the counter for a HOTP is 0. use OTPHP\TOTP; use OTPHP\HOTP; -$otp = TOTP::generate( - 10 // The period is now 10 seconds -); +$otp = TOTP::generate(); +$otp->setPeriod(10); // The period is now 10 seconds -$otp = HOTP::generate( - 1000 // The counter is now 1000. We recommend you start at `0`, but you can set any value (at least 0) -); +$otp = HOTP::generate(); +$otp->setCounter(1000); // The counter is now 1000. We recommend you start at `0`, but you can set any value (at least 0) ``` ## Digest @@ -57,10 +55,9 @@ You must verify that the algorithm you want to use is supported by the applicati setPeriod(30); // The period (30 seconds) +$totp->setDigest('ripemd160'); // The digest algorithm ``` ## Digits @@ -72,11 +69,10 @@ You can decide to use more (or less) digits. More than 10 may be difficult to us setPeriod(30); // The period (30 seconds) +$totp->setDigest('sha1'); // The digest algorithm +$totp->setDigits(8); // The output will generate 8 digits ``` ## Epoch (TOTP only) @@ -96,11 +92,10 @@ example encode the timestamp in the secret to make it different each time. use OTPHP\TOTP; // Without epoch -$otp = TOTP::generate( - 5, // The period (5 seconds) - 'sha1', // The digest algorithm - 6 // The output will generate 6 digits -); +$otp = TOTP::generate(); +$otp->setPeriod(5); // The period (5 seconds) +$otp->setDigest('sha1'); // The digest algorithm +$otp->setDigits(6); // The output will generate 6 digits $password = $otp->at(1519401289); // Current period is: 1519401285 - 1519401289 @@ -108,12 +103,11 @@ $otp->verify($password, 1519401289); // Second 1: true $otp->verify($password, 1519401290); // Second 2: false // With epoch -$otp = TOTP::generate( - 5, // The period (5 seconds) - 'sha1', // The digest algorithm - 6, // The output will generate 6 digits - 1519401289 // The epoch is now 02/23/2018 @ 3:54:49pm (UTC) -); +$otp = TOTP::generate(); +$otp->setPeriod(5); // The period (30 seconds) +$otp->setDigest('sha1'); // The digest algorithm +$otp->setDigits(6); // The output will generate 8 digits +$otp->setEpoch(1519401289); // The epoch is now 02/23/2018 @ 3:54:49pm (UTC) $password = $otp->at(1519401289); // Current period is: 1519401289 - 1519401293 diff --git a/doc/QA.md b/doc/QA.md index 369d9c1..a71f755 100644 --- a/doc/QA.md +++ b/doc/QA.md @@ -24,12 +24,10 @@ $digits = 6; $digest = 'sha1'; $period = 30; -$totp = TOTP::createFromSecret( - $user->getOtpSecret(), - $period, - $digest, - $digits -); +$totp = TOTP::createFromSecret($user->getOtpSecret()); +$totp->setPeriod($period); +$totp->setDigest($digest); +$totp->setDigits($digits); $totp->setLabel($user->getEmail()); $totp->verify($_POST['otp']);