Skip to content

Commit f6e3c66

Browse files
authored
Merge pull request #10 from aleho/feature/php-81
PHP 8.1
2 parents 3f8a689 + f160a12 commit f6e3c66

19 files changed

+355
-267
lines changed

.github/workflows/php.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ jobs:
1919
uses: shivammathur/setup-php@v2
2020
with:
2121
php-version: '8.2'
22+
coverage: xdebug
2223

2324
- name: Validate composer.json and composer.lock
2425
run: composer validate --no-check-publish
@@ -27,4 +28,4 @@ jobs:
2728
run: composer install --no-progress
2829

2930
- name: Run PHPUnit
30-
run: vendor/bin/phpunit
31+
run: vendor/bin/phpunit --coverage-text

README.md

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ The ALTCHA PHP Library is a lightweight, zero-dependency library designed for cr
66

77
This library is compatible with:
88

9-
- PHP 7.4+
9+
- PHP 8.1+
1010
- All major platforms (Linux, Windows, macOS)
1111

1212
## Example
@@ -33,16 +33,15 @@ require 'vendor/autoload.php';
3333
use AltchaOrg\Altcha\ChallengeOptions;
3434
use AltchaOrg\Altcha\Altcha;
3535

36-
$hmacKey = 'secret hmac key';
36+
$altcha = new Altcha('secret hmac key');
3737

3838
// Create a new challenge
3939
$options = new ChallengeOptions(
40-
$hmacKey,
41-
ChallengeOptions::DEFAULT_ALGORITHM,
42-
50000, // the maximum random number
40+
maxNumber: 50000, // the maximum random number
41+
expires: (new \DateTimeImmutable())->add(new \DateInterval('PT10S')),
4342
]);
4443

45-
$challenge = Altcha::createChallenge($options);
44+
$challenge = $altcha->createChallenge($options);
4645
echo "Challenge created: " . json_encode($challenge) . "\n";
4746

4847
// Example payload to verify
@@ -55,7 +54,7 @@ $payload = [
5554
];
5655

5756
// Verify the solution
58-
$ok = Altcha::verifySolution($payload, $hmacKey, true);
57+
$ok = $altcha->verifySolution($payload, true);
5958

6059
if ($ok) {
6160
echo "Solution verified!\n";
@@ -76,28 +75,26 @@ Creates a new challenge for ALTCHA.
7675

7776
```php
7877
$options = new ChallengeOptions(
79-
$hmacKey,
80-
ChallengeOptions::DEFAULT_ALGORITHM,
81-
ChallengeOptions::DEFAULT_MAX_NUMBER,
82-
(new \DateTimeImmutable())->add(new \DateInterval('PT10S')),
83-
['query_param' => '123'],
84-
ChallengeOptions::DEFAULT_SALT_LENGTH
78+
algorithm: ChallengeOptions::DEFAULT_ALGORITHM,
79+
maxNumber: ChallengeOptions::DEFAULT_MAX_NUMBER,
80+
expires: (new \DateTimeImmutable())->add(new \DateInterval('PT10S')),
81+
params: ['query_param' => '123'],
82+
saltLength: ChallengeOptions::DEFAULT_SALT_LENGTH
8583
]);
8684
```
8785

88-
### `Altcha::verifySolution(array|string $payload, string $hmacKey, bool $checkExpires): bool`
86+
### `Altcha::verifySolution(array|string $payload, bool $checkExpires): bool`
8987

9088
Verifies an ALTCHA solution.
9189

9290
**Parameters:**
9391

9492
- `data array|string`: The solution payload to verify.
95-
- `hmacKey string`: The HMAC key used for verification.
9693
- `checkExpires bool`: Whether to check if the challenge has expired.
9794

9895
**Returns:** `bool`
9996

100-
### `Altcha::verifyFieldsHash(array $formData, array $fields, string $fieldsHash, string $algorithm): bool`
97+
### `Altcha::verifyFieldsHash(array $formData, array $fields, string $fieldsHash, Algorithm $algorithm): bool`
10198

10299
Verifies the hash of form fields.
103100

@@ -110,18 +107,17 @@ Verifies the hash of form fields.
110107

111108
**Returns:** `bool`
112109

113-
### `Altcha::verifyServerSignature(array|string $payload, string $hmacKey): ServerSignatureVerification`
110+
### `Altcha::verifyServerSignature(array|string $payload): ServerSignatureVerification`
114111

115112
Verifies the server signature.
116113

117114
**Parameters:**
118115

119116
- `data array|string`: The payload to verify (string or `ServerSignaturePayload` array).
120-
- `hmacKey string`: The HMAC key used for verification.
121117

122118
**Returns:** `ServerSignatureVerification`
123119

124-
### `Altcha::solveChallenge(string $challenge, string $salt, string $algorithm, int $max, int $start = 0): array`
120+
### `Altcha::solveChallenge(string $challenge, string $salt, Algorithm $algorithm, int $max, int $start = 0): array`
125121

126122
Finds a solution to the given challenge.
127123

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
}
1515
],
1616
"require": {
17-
"php": ">=7.4",
17+
"php": ">=8.1",
1818
"ext-json": "*"
1919
},
2020
"require-dev": {

composer.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Algorithm.php

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)