gisostallenberg / fixed-token
This package is abandoned and no longer maintained.
The author suggests using the stdlib (hash_hmac + hash_equals) package instead.
There is no license information available for the latest version (1.0.0) of this package.
Generates and verifies tokens based on a secret and some public data
1.0.0
2017-01-27 15:41 UTC
Requires
None
Requires (Dev)
- phpunit/phpunit: ^5.7
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-10-27 20:30:34 UTC
README
Generate and verify tokens based on a secret and some public data
⚠️ Do not use this package
It is insecure and unnecessary. Two flaws, both fatal for a security token:
- Length-extension attack.
generate()returnssha1($secret . $data). SHA-1 is a Merkle–Damgård hash, so anyone holding a single valid(data, token)pair can forge a valid token for extended data without knowing the secret. The construction that prevents this is HMAC.- Timing attack.
verify()compares with===, which stops at the first differing byte and leaks the match length, allowing a byte-by-byte forgery. MAC comparison must be constant-time (hash_equals()).Both are solved by PHP's standard library — no dependency needed.
hash_hmacandhash_equalsare built in (hash_equalssince PHP 5.6):$payload = http_build_query($data); // ksort($data) first for a stable order // generate $token = hash_hmac('sha256', $payload, $secret); // verify (constant-time) hash_equals($token, $givenToken); // boolIf you need expiry, claims or revocation rather than a bare tag, use a maintained, reviewed library such as paragonie/paseto or firebase/php-jwt.
Installation
composer require gisostallenberg/fixed-token
Usage example
<?php use GisoStallenberg\FixedToken\FixedToken; $secret = 'oxQu/H2FZLOK2elkfle8bg./eg'; $data = array( 'username' => 'giso', ); $token = FixedToken::create($secret) ->addData($data) ->generate(); FixedToken::create($secret) ->addData($data) ->verify($token); // should return true