Skip to content

Commit 241f12c

Browse files
Merge pull request #3 from HichemTab-tech/make-the-package-compatible-with-php-7.1
transform to php 7.1
2 parents d8f3ddc + 7791bf5 commit 241f12c

File tree

1 file changed

+46
-36
lines changed

1 file changed

+46
-36
lines changed

README.md

Lines changed: 46 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ TokensValidation is a PHP library designed to generate and verify authentication
3232

3333
## Installation
3434

35+
> ⚠️ **WARNING**: This version is compatible with PHP 7.1. If you are using PHP 8, it is recommended to use the [latest version](https://github.com/HichemTab-tech/tokens-validation) of this library.
36+
3537
The TokensValidation library can be installed via Composer by running the following command:
3638

3739
```bash
@@ -89,14 +91,17 @@ The First example is an Auto generating and verifying:
8991
- To generate an authentication token using cookies, call the following method:
9092
```PHP
9193
$authToken = TokensValidation::createNewAuthToken(
92-
userId: $uid,
93-
usingCookies: true
94+
$uid,
95+
"",
96+
true
9497
);
9598

9699
// you can print $authToken for additional informations about the created token.
97100
```
98101
This method generates a new authentication token for the given user ID and saves it in a cookie. The second argument specifies whether to use cookies or not.
99102

103+
> ⚠️ It's **highly recommended** to use the [latest version](https://github.com/HichemTab-tech/tokens-validation) of the library which is compatible with **PHP 8.0** and above.
104+
100105
To check the authentication token, call the following method:
101106
```PHP
102107
$result = TokensValidation::checkAuthToken();
@@ -130,8 +135,9 @@ To generate an authentication token and handle it yourself, call the following m
130135

131136
```PHP
132137
$authToken = TokensValidation::createNewAuthToken(
133-
userId: $uid,
134-
usingCookies: false
138+
$uid,
139+
"",
140+
false
135141
);
136142

137143
echo $authToken->getUserId();
@@ -195,14 +201,14 @@ You can add an extra layer of security to authentication tokens by using a brows
195201

196202
```PHP
197203
$authToken = TokensValidation::createNewAuthToken(
198-
userId: $uid,
199-
fingerPrint: $somefingerprint
204+
$uid,
205+
$somefingerprint
200206
);
201207
```
202208
To check the authentication token with a fingerprint, call the **checkAuthToken()** method with the fingerprint argument.
203209

204210
```PHP
205-
$result = TokensValidation::checkAuthToken(authToken: $authToken, fingerPrint: $somefingerprint);
211+
$result = TokensValidation::checkAuthToken($somefingerprint, $authToken);
206212
```
207213

208214
- *to generate the fingerprint, you can use for example https://github.com/Valve/fingerprintjs2*
@@ -220,8 +226,8 @@ In this case, the library generates a lengthy token that includes an encrypted u
220226

221227
```PHP
222228
$confirmationToken = TokensValidation::createNewConfirmationToken(
223-
userId: $uid,
224-
confirmationType: ConfirmationsTokenTypes::IN_URL
229+
$uid,
230+
ConfirmationsTokenTypes::IN_URL
225231
);
226232

227233
echo $confirmationToken->getContent();// if you want to view the long confirmation token
@@ -234,7 +240,7 @@ $confirmationToken = TokensValidation::createNewConfirmationToken(
234240
You can utilize these lines of code to verify the contents of a URL.
235241

236242
```PHP
237-
$result = TokensValidation::checkConfirmationUrl(url: $url);
243+
$result = TokensValidation::checkConfirmationUrl($url);
238244
if ($result->isValidationSucceed()) {
239245
//for example :
240246
echo $result->getUserId();
@@ -248,7 +254,7 @@ $result = TokensValidation::checkConfirmationUrl(url: $url);
248254
Or you can inject **$_GET** directly:
249255

250256
```PHP
251-
$result = TokensValidation::checkConfirmationUrlParamsFromGET(_GET_ARRAY: $_GET);
257+
$result = TokensValidation::checkConfirmationUrlParamsFromGET($_GET);
252258
```
253259

254260
To override the ConfirmationUrl builder methods, create a class that extends the **ConfirmationUrlBuilder** class and implements the **getUrl(ConfirmationToken $confirmationToken, string $baseUrl)**, **getUserIdAndTokenFromUrl(string $url)**, and **getUserIdAndTokenFromGET(array $_GET_ARRAY)** methods. Then, set the $ConfirmationUrlBuilder property to the name of your new class. Here's an example:
@@ -297,14 +303,14 @@ In this case, the user needs to enter the confirmation token generated by the li
297303

298304
```PHP
299305
$confirmationToken = TokensValidation::createNewConfirmationToken(
300-
userId: $uid,
301-
confirmationType: ConfirmationsTokenTypes::SMALL_CODE
306+
$uid,
307+
ConfirmationsTokenTypes::SMALL_CODE
302308
);
303309

304310
echo $confirmationToken->getContent();
305311

306312

307-
$result = TokensValidation::checkConfirmationCode(code: $token);
313+
$result = TokensValidation::checkConfirmationCode($token);
308314
if ($result->isValidationSucceed()) {
309315
//for example :
310316
echo $result->getUserId();
@@ -320,16 +326,16 @@ To ensure that each confirmation code is used for its intended purpose, you can
320326

321327
```PHP
322328
$confirmationToken = TokensValidation::createNewConfirmationToken(
323-
userId: $uid,
324-
confirmationType: ConfirmationsTokenTypes::SMALL_CODE,
325-
whatFor: "email-confirmation"
329+
$uid,
330+
ConfirmationsTokenTypes::SMALL_CODE,
331+
"email-confirmation"
326332
);
327333
```
328334

329335

330336
To check it :
331337
```PHP
332-
$result = TokensValidation::checkConfirmationCode(code: $token, whatFor: "email-confirmation");
338+
$result = TokensValidation::checkConfirmationCode($token, null, "email-confirmation");
333339
```
334340

335341
If the "whatFor" parameter does not match the intended purpose of the confirmation code, the validation process will fail.
@@ -340,10 +346,10 @@ you want just to check the token if its valid, then check it later in another po
340346
This parameter allows you to specify whether the token will be deleted after the validation succeeded or not.
341347

342348
```PHP
343-
$confirmationToken = TokensValidation::createNewConfirmationToken(
344-
userId: $uid,
345-
confirmationType: ConfirmationsTokenTypes::SMALL_CODE,
346-
whatFor: "email-confirmation",
349+
$confirmationToken = TokensValidation::checkConfirmationCode(
350+
$uid,
351+
ConfirmationsTokenTypes::SMALL_CODE,
352+
"email-confirmation",
347353
deleteAfterCheck: false, //true by default
348354
);
349355
```
@@ -357,10 +363,11 @@ the library returns the existed token only with different expiration date.
357363

358364
```PHP
359365
$confirmationToken = TokensValidation::createNewConfirmationToken(
360-
userId: $uid,
361-
confirmationType: ConfirmationsTokenTypes::SMALL_CODE,
362-
whatFor: "email-confirmation",
363-
singleTokenPerTime: true
366+
$uid,
367+
ConfirmationsTokenTypes::SMALL_CODE,
368+
"email-confirmation",
369+
-1,
370+
true
364371
);
365372
```
366373

@@ -391,8 +398,10 @@ TokensValidation::setConfirmationTokenExpirationDelay(60 * 60); // seconds
391398
You have the option to provide a custom expiration delay by passing the "expirationDelay" parameter to the function which generates the token for either the confirmation token or authentication token. You can accomplish this by using the following code:
392399
```PHP
393400
$confirmationToken = TokensValidation::createNewConfirmationToken(
394-
userId: $uid,
395-
expirationDelay: 60*60 // seconds
401+
$uid,
402+
ConfirmationsTokenTypes::SMALL_CODE,
403+
"default",
404+
60*60 // seconds
396405
);
397406
```
398407

@@ -436,9 +445,10 @@ you can create an invitation by calling this code:
436445

437446
```PHP
438447
$invitation = TokensValidation::createInvitation(
439-
userId: $uid,
440-
target_email: "user@example.com",
441-
whatFor: "become-admin",
448+
$uid,
449+
"user@example.com",
450+
-1,
451+
"become-admin",
442452
);
443453

444454
echo $invitation->getUrl();
@@ -463,8 +473,8 @@ Typically, when using the invitation feature for actions such as sign up, the us
463473
<?php
464474

465475
$invitation = TokensValidation::checkInvitationToken(
466-
token: $_GET['token'],
467-
whatFor: "administration",
476+
$_GET['token'],
477+
"administration",
468478
);
469479

470480
if (!$invitation->isValidationSucceed()) {
@@ -492,9 +502,9 @@ After the user inputs the required information and submits the form, the token n
492502
...
493503

494504
$invitation = TokensValidation::checkInvitationToken(
495-
token: $_GET['token'],
496-
whatFor: "administration",
497-
thenAccept: true
505+
$_GET['token'],
506+
"administration",
507+
true
498508
);
499509

500510
if (!$invitation->isValidationSucceed()) {

0 commit comments

Comments
 (0)