Commit 8c05e668 authored by Filippo Tessarotto's avatar Filippo Tessarotto Committed by Florent Morselli
Browse files

Update Doc

Showing with 20 additions and 26 deletions
+20 -26
......@@ -15,7 +15,7 @@ You just have to:
<?php
use OTPHP\TOTP;
$totp = TOTP::create('JBSWY3DPEHPK3PXP'); // New TOTP with custom secret
$totp = TOTP::createFromSecret('JBSWY3DPEHPK3PXP'); // New TOTP with custom secret
$totp->setLabel('alice@google.com'); // The label (string)
$totp->getProvisioningUri(); // Will return otpauth://totp/alice%40google.com?secret=JBSWY3DPEHPK3PXP
......@@ -34,7 +34,7 @@ Hereafter two examples using the Google Chart API (this API is deprecated since
<?php
use OTPHP\TOTP;
$totp = TOTP::create(); // New TOTP
$totp = TOTP::generate(); // New TOTP
$totp->setLabel('alice@google.com'); // The label (string)
$google_chart = $totp->getQrCodeUri('https://chart.googleapis.com/chart?chs=200x200&chld=M|0&cht=qr&chl={PROVISIONING_URI}', '{PROVISIONING_URI}');
......@@ -48,7 +48,7 @@ Please note that this URI MUST contain a placeholder for the OTP Provisioning UR
<?php
use OTPHP\TOTP;
$totp = TOTP::create(); // New TOTP
$totp = TOTP::generate(); // New TOTP
$totp->setLabel('alice@google.com'); // The label (string)
$goqr_me = $totp->getQrCodeUri(
......@@ -74,7 +74,7 @@ Now run the following and compare the output
<?php
use OTPHP\TOTP;
$totp = TOTP::create('JBSWY3DPEHPK3PXP'); // New TOTP with custom secret
$totp = TOTP::createFromSecret('JBSWY3DPEHPK3PXP'); // New TOTP with custom secret
$totp->setLabel('alice@google.com'); // The label (string)
echo 'Current OTP: ' . $totp->now();
......@@ -92,7 +92,7 @@ Now run the following and compare the output
<?php
use OTPHP\TOTP;
$totp = TOTP::create(
$totp = TOTP::createFromSecret(
'JBSWY3DPEHPK3PXP', // New TOTP with custom secret
10, // The period (int)
'sha512', // The digest algorithm (string)
......
......@@ -21,7 +21,7 @@ use OTPHP\TOTP;
use ParagonIE\ConstantTime\Base32;
$mySecret = trim(Base32::encodeUpper(random_bytes(128)), '='); // We generate our own 1024 bits secret
$otp = TOTP::create($mySecret);
$otp = TOTP::createFromSecret($mySecret);
```
*Please note that the trailing `=` are automatically removed by the library.*
......@@ -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::create(
null, // Let the secret be defined by the class
$otp = TOTP::generate(
10 // The period is now 10 seconds
);
$otp = HOTP::create(
null, // Let the secret be defined by the class
$otp = HOTP::generate(
1000 // The counter is now 1000. We recommend you start at `0`, but you can set any value (at least 0)
);
```
......@@ -59,8 +57,7 @@ You must verify that the algorithm you want to use is supported by the applicati
<?php
use OTPHP\TOTP;
$totp = TOTP::create(
null, // Let the secret be defined by the class
$totp = TOTP::generate(
30, // The period (30 seconds)
'ripemd160' // The digest algorithm
);
......@@ -75,8 +72,7 @@ You can decide to use more (or less) digits. More than 10 may be difficult to us
<?php
use OTPHP\TOTP;
$totp = TOTP::create(
null, // Let the secret be defined by the class
$totp = TOTP::generate(
30, // The period (30 seconds)
'sha1', // The digest algorithm
8 // The output will generate 8 digits
......@@ -100,8 +96,7 @@ example encode the timestamp in the secret to make it different each time.
use OTPHP\TOTP;
// Without epoch
$otp = TOTP::create(
null, // Let the secret be defined by the class
$otp = TOTP::generate(
5, // The period (5 seconds)
'sha1', // The digest algorithm
6 // The output will generate 6 digits
......@@ -113,8 +108,7 @@ $otp->verify($password, 1519401289); // Second 1: true
$otp->verify($password, 1519401290); // Second 2: false
// With epoch
$otp = TOTP::create(
null, // Let the secret be defined by the class
$otp = TOTP::generate(
5, // The period (5 seconds)
'sha1', // The digest algorithm
6, // The output will generate 6 digits
......@@ -140,7 +134,7 @@ These parameters are available in the provisioning URI or from the method `getPa
<?php
use OTPHP\TOTP;
$totp = TOTP::create('JBSWY3DPEHPK3PXP'); // New TOTP
$totp = TOTP::createFromSecret('JBSWY3DPEHPK3PXP'); // New TOTP
$totp->setLabel('alice@google.com'); // The label
$totp->setParameter('foo', 'bar');
......@@ -156,7 +150,7 @@ it is useful to set the issuer parameter to identify the service that provided t
<?php
use OTPHP\TOTP;
$totp = TOTP::create('JBSWY3DPEHPK3PXP'); // New TOTP with custom secret
$totp = TOTP::createFromSecret('JBSWY3DPEHPK3PXP'); // New TOTP with custom secret
$totp->setLabel('alice@google.com'); // The label (string)
$totp->setIssuer('My Service');
```
......@@ -187,7 +181,7 @@ Some applications such as FreeOTP can load images from an URI (`image` parameter
<?php
use OTPHP\TOTP;
$totp = TOTP::create('JBSWY3DPEHPK3PXP'); // New TOTP with custom secret
$totp = TOTP::createFromSecret('JBSWY3DPEHPK3PXP'); // New TOTP with custom secret
$totp->setLabel('alice@google.com'); // The label (string)
$totp->setParameter('image', 'https://foo.bar/otp.png');
......
......@@ -24,7 +24,7 @@ $digits = 6;
$digest = 'sha1';
$period = 30;
$totp = TOTP::create(
$totp = TOTP::createFromSecret(
$user->getOtpSecret(),
$period,
$digest,
......@@ -76,7 +76,7 @@ If you try the following code lines, you may see 2 different OTPs.
<?php
use OTPHP\TOTP;
$totp = TOTP::create(null, 10); // TOTP with an 10 seconds period
$totp = TOTP::generate(10); // TOTP with an 10 seconds period
for ($i = 0; $i < 10; $i++) {
echo 'Current OTP is: '. $totp->now();
......
......@@ -42,13 +42,13 @@ use OTPHP\TOTP;
// A random secret will be generated from this.
// You should store the secret with the user for verification.
$otp = TOTP::create();
$otp = TOTP::generate();
echo "The OTP secret is: {$otp->getSecret()}\n";
// Note: use your own way to load the user secret.
// The function "load_user_secret" is simply a placeholder.
$secret = load_user_secret();
$otp = TOTP::create($secret);
$otp = TOTP::createFromSecret($secret);
echo "The current OTP is: {$otp->now()}\n";
```
......@@ -74,7 +74,7 @@ echo "<img src='{$grCodeUri}'>";
Now that your applications are configured, you can verify the generated OTPs:
```php
$otp = TOTP::create($secret); // create TOTP object from the secret.
$otp = TOTP::createFromSecret($secret); // create TOTP object from the secret.
$otp->verify($input); // Returns true if the input is verified, otherwise false.
```
......
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