You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Copy file name to clipboardexpand all lines: doc/index.md
+11-3
Original file line number
Diff line number
Diff line change
@@ -34,21 +34,25 @@ You have to verify that the server and the device are synchronized.
34
34
35
35
# How to use
36
36
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.
38
40
39
41
```php
40
42
<?php
41
43
use OTPHP\TOTP;
42
44
45
+
$clock = new MyClock(); // Your own implementation of a PSR-20 Clock
46
+
43
47
// A random secret will be generated from this.
44
48
// You should store the secret with the user for verification.
45
-
$otp = TOTP::generate();
49
+
$otp = TOTP::generate($clock);
46
50
echo "The OTP secret is: {$otp->getSecret()}\n";
47
51
48
52
// Note: use your own way to load the user secret.
49
53
// The function "load_user_secret" is simply a placeholder.
50
54
$secret = load_user_secret();
51
-
$otp = TOTP::createFromSecret($secret);
55
+
$otp = TOTP::createFromSecret($secret, $clock);
52
56
echo "The current OTP is: {$otp->now()}\n";
53
57
```
54
58
@@ -57,6 +61,10 @@ In the example above, we use the `TOTP` class, but you can use the `HOTP` one th
57
61
Then, you have to configure your applications.
58
62
You can use the provisioning Uri (`$otp->getProvisioningUri();`) as QR Code input to easily configure all of them.
59
63
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
+
60
68
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)).
0 commit comments