Commit 9170b8e9 authored by Filippo Tessarotto's avatar Filippo Tessarotto Committed by Florent Morselli
Browse files

Update doc as well

Showing with 29 additions and 39 deletions
+29 -39
......@@ -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();
```
......@@ -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
......
......@@ -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']);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment