php-standard-library/hash
Hash utilities for PHP: cryptographic and non-cryptographic hashing via an Algorithm enum, HMAC helpers, and timing-safe string comparison. Lightweight package from PHP Standard Library for consistent, secure hashing across projects.
Hash facade (passwords) or other cryptographic layers (e.g., Illuminate\Encryption). Ideal for non-password hashing (e.g., checksums, tokens, audit logs) where consistency is critical.hash() calls (e.g., replacing md5() or sha1()).app('hash')->generate()), bridging the gap with Laravel’s Hash facade.Hash facade (passwords) to prevent confusion.Hash facade if not scoped strictly to non-password use cases. Mitigate by documenting clear boundaries (e.g., "Use this for data integrity, not passwords").Hash if the package stagnates.hash_equals() for critical paths (e.g., high-throughput APIs).Hash::standard()) or used directly in services?hash() calls be phased out? Use static analysis tools (e.g., PHPStan) to detect remaining ad-hoc hashing.ext-hash, ext-sodium) or frameworks (Symfony, Lumen).Hash facade: Use for passwords only (argon2id/bcrypt).SecurityComponent: If using Symfony’s hashing utilities.hash() call (e.g., md5()) with the package’s equivalent to validate behavior.sha1(), crc32()) with the package’s API.// Before
$checksum = md5(file_get_contents($file));
// After
$checksum = app('hash')->generate(file_get_contents($file), 'md5');
$this->app->singleton('hash', function () {
return new \PhpStandardLibrary\Hash\HashGenerator();
});
public function __construct(private HashGenerator $hash) {}
argon2i for passwords should not use this package).Hash facade—keep passwords separate to prevent logic duplication.composer require php-standard-library/hash
hash() calls.config('hash.use_standard_library')) for gradual adoption.hash() calls.composer.json to avoid breaking changes.hash() if needed.HashComparator.hash() calls.| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Algorithm removed in update | Breaks hashing logic | Pin version in composer.json |
| Timing-attack vulnerability | Security risk in comparisons | Use package’s HashComparator |
| PHP version incompatibility | Package fails to load | Test on CI with target PHP versions |
| Algorithm collision | False positives in comparisons | Validate against native hash() outputs |
| Dependency conflicts | Breaks Laravel core functionality | Test in isolation before full adoption |
hash_equals().// UNSAFE (timing attack risk)
$input === $storedHash;
// SAFE
$comparator->compare($input, $storedHash);
composer why php-standard-library/hash in CI.hash() calls using static analysis tools.How can I help you explore Laravel packages today?