Skip to content
GitLab
Explore
Projects
Groups
Topics
Snippets
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
fusiondirectory
otphp
Commits
9170b8e9
Commit
9170b8e9
authored
2 years ago
by
Filippo Tessarotto
Committed by
Florent Morselli
2 years ago
Browse files
Options
Download
Patches
Plain Diff
Update doc as well
parent
0d3f92d6
11.2.x
11.0.x
11.1.x
dependabot/composer/phpunit/phpunit-tw-9.5.26or-tw-10.0.0
11.1.0
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
doc/AppConfig.md
+5
-7
doc/AppConfig.md
doc/Customize.md
+20
-26
doc/Customize.md
doc/QA.md
+4
-6
doc/QA.md
with
29 additions
and
39 deletions
+29
-39
doc/AppConfig.md
+
5
−
7
View file @
9170b8e9
...
...
@@ -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
();
```
This diff is collapsed.
Click to expand it.
doc/Customize.md
+
20
−
26
View file @
9170b8e9
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
doc/QA.md
+
4
−
6
View file @
9170b8e9
...
...
@@ -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'
]);
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Topics
Snippets