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
8c05e668
Commit
8c05e668
authored
2 years ago
by
Filippo Tessarotto
Committed by
Florent Morselli
2 years ago
Browse files
Options
Download
Patches
Plain Diff
Update Doc
parent
0ff609bb
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
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
doc/AppConfig.md
+5
-5
doc/AppConfig.md
doc/Customize.md
+10
-16
doc/Customize.md
doc/QA.md
+2
-2
doc/QA.md
doc/index.md
+3
-3
doc/index.md
with
20 additions
and
26 deletions
+20
-26
doc/AppConfig.md
+
5
−
5
View file @
8c05e668
...
...
@@ -15,7 +15,7 @@ You just have to:
<?php
use
OTPHP\TOTP
;
$totp
=
TOTP
::
create
(
'JBSWY3DPEHPK3PXP'
);
// New TOTP with custom secret
$totp
=
TOTP
::
create
FromSecret
(
'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
::
cre
ate
();
// New TOTP
$totp
=
TOTP
::
gener
ate
();
// 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
::
cre
ate
();
// New TOTP
$totp
=
TOTP
::
gener
ate
();
// 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
::
create
FromSecret
(
'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
::
create
FromSecret
(
'JBSWY3DPEHPK3PXP'
,
// New TOTP with custom secret
10
,
// The period (int)
'sha512'
,
// The digest algorithm (string)
...
...
This diff is collapsed.
Click to expand it.
doc/Customize.md
+
10
−
16
View file @
8c05e668
...
...
@@ -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
::
create
FromSecret
(
$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
::
create
FromSecret
(
'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
::
create
FromSecret
(
'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
::
create
FromSecret
(
'JBSWY3DPEHPK3PXP'
);
// New TOTP with custom secret
$totp
->
setLabel
(
'alice@google.com'
);
// The label (string)
$totp
->
setParameter
(
'image'
,
'https://foo.bar/otp.png'
);
...
...
This diff is collapsed.
Click to expand it.
doc/QA.md
+
2
−
2
View file @
8c05e668
...
...
@@ -24,7 +24,7 @@ $digits = 6;
$digest
=
'sha1'
;
$period
=
30
;
$totp
=
TOTP
::
create
(
$totp
=
TOTP
::
create
FromSecret
(
$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
();
...
...
This diff is collapsed.
Click to expand it.
doc/index.md
+
3
−
3
View file @
8c05e668
...
...
@@ -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
::
cre
ate
();
$otp
=
TOTP
::
gener
ate
();
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
::
create
FromSecret
(
$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
::
create
FromSecret
(
$secret
);
// create TOTP object from the secret.
$otp
->
verify
(
$input
);
// Returns true if the input is verified, otherwise false.
```
...
...
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