Skip to content

Commit 5ccef72

Browse files
committed
Update OTP method to require PSR-20 Clock
The `create` method is now renamed to `generate` and requires a PSR-20 Clock as the first argument from version 11.4+. Updated documentation to reflect this change and recommend early adoption to avoid future issues.
1 parent 2d8ccb5 commit 5ccef72

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

doc/index.md

+11-3
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,25 @@ You have to verify that the server and the device are synchronized.
3434

3535
# How to use
3636

37-
To create an OTP object, just use the static `create` method. Your object will be able to generate passwords:
37+
To create an OTP object, just use the static `generate` method. Your object will be able to generate passwords.
38+
Note that the method will require a PSR-20 Clock in the next major release.
39+
It is higly recommended to pass it as first argument to the `generate` method in version 11.4+ to avoid any issue in the future.
3840

3941
```php
4042
<?php
4143
use OTPHP\TOTP;
4244

45+
$clock = new MyClock(); // Your own implementation of a PSR-20 Clock
46+
4347
// A random secret will be generated from this.
4448
// You should store the secret with the user for verification.
45-
$otp = TOTP::generate();
49+
$otp = TOTP::generate($clock);
4650
echo "The OTP secret is: {$otp->getSecret()}\n";
4751

4852
// Note: use your own way to load the user secret.
4953
// The function "load_user_secret" is simply a placeholder.
5054
$secret = load_user_secret();
51-
$otp = TOTP::createFromSecret($secret);
55+
$otp = TOTP::createFromSecret($secret, $clock);
5256
echo "The current OTP is: {$otp->now()}\n";
5357
```
5458

@@ -57,6 +61,10 @@ In the example above, we use the `TOTP` class, but you can use the `HOTP` one th
5761
Then, you have to configure your applications.
5862
You can use the provisioning Uri (`$otp->getProvisioningUri();`) as QR Code input to easily configure all of them.
5963

64+
The provision URI can be stored in your database (or any other storage) and used to generate back the OTP object (see [Factory](Factory.md)).
65+
66+
```php
67+
6068
We recommend you to use your own QR Code generator (e.g. [BaconQrCode](https://packagist.org/packages/bacon/bacon-qr-code) or [endroid/qr-code](https://github.com/endroid/qr-code)).
6169

6270
```php

0 commit comments

Comments
 (0)