Skip to content

Commit

Permalink
Update doc as well
Browse files Browse the repository at this point in the history
  • Loading branch information
Slamdunk authored and Spomky committed Nov 5, 2022
1 parent 0d3f92d commit 9170b8e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 39 deletions.
12 changes: 5 additions & 7 deletions doc/AppConfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -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('[email protected]'); // 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('[email protected]'); // The label (string)

echo 'Current OTP: ' . $totp->now();
```
46 changes: 20 additions & 26 deletions doc/Customize.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -96,24 +92,22 @@ 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

$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

Expand Down
10 changes: 4 additions & 6 deletions doc/QA.md
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down

0 comments on commit 9170b8e

Please sign in to comment.