@@ -6,7 +6,7 @@ The ALTCHA PHP Library is a lightweight, zero-dependency library designed for cr
66
77This 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';
3333use AltchaOrg\Altcha\ChallengeOptions;
3434use 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);
4645echo "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
6059if ($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
9088Verifies 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
10299Verifies 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
115112Verifies 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
126122Finds a solution to the given challenge.
127123
0 commit comments