diff --git a/doc/AppConfig.md b/doc/AppConfig.md index 5f2a4ef82bf7ab76621bf836455067600dad5b54..486cd5214fb30fd76ed3e810256b605de2927d46 100644 --- a/doc/AppConfig.md +++ b/doc/AppConfig.md @@ -92,13 +92,11 @@ Now run the following and compare the output <?php use OTPHP\TOTP; -$totp = TOTP::createFromSecret( - 'JBSWY3DPEHPK3PXP', // New TOTP with custom secret - 10, // The period (int) - 'sha512', // The digest algorithm (string) - 8 // The number of digits (int) -); -$totp->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 db57894122bc44cc02c4e6c9fabb69e61da63a76..47964204174a9945e6b0ef362457d41668d5e06a 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 <?php use OTPHP\TOTP; -$totp = TOTP::generate( - 30, // The period (30 seconds) - 'ripemd160' // The digest algorithm -); +$totp = TOTP::generate(); +$totp->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 <?php use OTPHP\TOTP; -$totp = TOTP::generate( - 30, // The period (30 seconds) - 'sha1', // The digest algorithm - 8 // The output will generate 8 digits -); +$totp = TOTP::generate(); +$totp->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 369d9c1250e75ecb9a43627576afc9964f38f0aa..a71f7552d133289b4ea11aa8f0cd91103b66ebde 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']);