Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Password Hasher Laravel Package

symfony/password-hasher

Symfony PasswordHasher provides secure password hashing and verification utilities. Configure multiple algorithms via PasswordHasherFactory (bcrypt, sodium/Argon2, etc.), hash plain passwords, verify hashes, and support upgrades with modern best practices.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture fit: The symfony/password-hasher package excels in security-first architectures where compliance (NIST SP 800-63B, OWASP, GDPR) and algorithm flexibility are critical. Its factory-based design enables multi-algorithm support (Argon2, bcrypt, sodium) and auto-migration, which aligns with Laravel’s need for secure authentication but requires a custom integration layer due to Laravel’s facade-centric Hash system. The package’s declarative configuration (e.g., PasswordHasherFactory) contrasts with Laravel’s implicit hashing, necessitating an adapter to expose Symfony’s features (e.g., needsRehash()) through Laravel’s HashContract. For projects with legacy hashes, tiered security, or compliance mandates, this is a high-value fit; for simple bcrypt use cases, the overhead may not be justified.

Technical risk:

  • Adapter complexity: Building a Laravel-compatible wrapper introduces risk of edge-case mismatches (e.g., hash format validation, algorithm-specific errors).
  • Database schema constraints: Argon2 hashes require VARCHAR(255+) columns, which may conflict with existing schemas.
  • Dependency bloat: Adding Symfony’s component (even as a standalone package) increases composer.lock size and potential for version conflicts with other Symfony packages.
  • Legacy hash support: Ensuring backward compatibility with SHA-1/MD5 hashes (if present) requires additional logic in the adapter.
  • Performance tuning: Argon2’s memory-hard parameters may impact login latency if not optimized for the target environment.

Key questions:

  1. Security requirements:
    • Does the project need Argon2/sodium for compliance (e.g., PCI DSS, GDPR) or tiered security (e.g., admins vs. users)?
    • Are there legacy hashes (SHA-1, MD5) that must be migrated incrementally?
  2. Integration effort:
    • Is the team willing to build/maintain a Laravel adapter (or use an existing one like spatie/laravel-password-hasher)?
    • Can the database schema accommodate Argon2’s longer hashes (255+ chars)?
  3. Performance tradeoffs:
    • Are there high-traffic endpoints where Argon2’s memory cost could cause latency?
    • Is there a baseline for acceptable hash verification time (e.g., <50ms)?
  4. Dependency management:
    • Will adding this package conflict with existing Symfony components (e.g., symfony/security-bundle)?
    • Is the team comfortable with Symfony’s release cycle (e.g., PHP 8.4+ requirement)?
  5. Migration strategy:
    • Should hashes be upgraded automatically (via auto algorithm) or manually?
    • Are there user-facing notifications needed during hash migration?

Integration Approach

Stack fit: The package is PHP/Laravel-compatible but requires intentional adaptation due to Laravel’s facade-based Hash system versus Symfony’s factory pattern. Key compatibility considerations:

  • Laravel’s Hash facade (Hash::make(), Hash::check()) must be wrapped or extended to use PasswordHasherFactory.
  • Service container integration: The factory should be registered as a Laravel service provider (e.g., HashServiceProvider) to replace or extend the default Hash implementation.
  • Algorithm mapping: Laravel’s default bcrypt must be aliased to Symfony’s bcrypt hasher, while adding support for argon2id, sodium, etc.
  • Hash format compatibility: Argon2’s longer output (e.g., argon2id$v=19$m=65536...) may require database schema updates or a polyfill layer for legacy systems.

Migration path:

  1. Assessment phase:
    • Audit existing hashes (identify algorithms, schema constraints).
    • Define security tiers (e.g., Argon2 for admins, bcrypt for users).
  2. Adapter development:
    • Create a SymfonyHashAdapter implementing HashContract to bridge PasswordHasherFactory and Laravel’s Hash facade.
    • Example:
      class SymfonyHashAdapter implements HashContract {
          public function make($value, array $options = []): string {
              return $this->factory->getPasswordHasher($options['algorithm'] ?? 'auto')->hash($value);
          }
          public function check($value, $hashedValue, array $options = []): bool {
              return $this->factory->getPasswordHasher($options['algorithm'] ?? 'auto')->verify($hashedValue, $value);
          }
          public function needsRehash($hashedValue, array $options = []): bool {
              return $this->factory->getPasswordHasher($options['algorithm'] ?? 'auto')->isPasswordTooOld($hashedValue);
          }
      }
      
  3. Configuration:
    • Register the adapter in config/app.php or a custom HashServiceProvider.
    • Example config/hash.php:
      'algorithms' => [
          'default' => 'bcrypt',
          'admin' => ['algorithm' => 'argon2id', 'memory_cost' => 65536],
      ],
      
  4. Database migration:
    • Update users.password column to VARCHAR(255) if using Argon2.
    • Add a hash_algorithm column (optional) to track algorithm per user.
  5. Phased rollout:
    • Stage 1: Replace Hash::make() with the adapter for new users (using auto algorithm).
    • Stage 2: Migrate legacy hashes via a login-triggered rehash (using needsRehash()).
    • Stage 3: Enforce tiered algorithms (e.g., Argon2 for admins).

Compatibility:

  • Laravel 10+: Fully compatible with PHP 8.1+ (Symfony 6.4+) or PHP 8.4+ (Symfony 8.0+).
  • Legacy Laravel: May require backporting or polyfills for older versions (e.g., PHP 7.4).
  • Symfony dependencies: Avoid conflicts by using standalone symfony/password-hasher (no symfony/security-bundle).
  • Third-party packages: Test compatibility with packages like laravel/sanctum or spatie/laravel-permission, which may assume Laravel’s default Hash behavior.

Sequencing:

  1. Pre-integration:
    • Benchmark hashing/verification latency for target algorithms (e.g., Argon2 with varying memory costs).
    • Update CI/CD pipelines to test the adapter with all supported algorithms.
  2. Integration:
    • Replace Hash facade in authentication logic (e.g., LoginController, RegisterController).
    • Update password reset flows to use the new adapter.
  3. Migration:
    • Deploy a feature flag to toggle between old/new hashing.
    • Monitor needsRehash() calls to track migration progress.
  4. Post-launch:
    • Audit logs for hashing failures (e.g., unsupported algorithms).
    • Optimize Argon2 parameters based on performance metrics.

Operational Impact

Maintenance:

  • Dependency updates: Monitor Symfony’s security patches (e.g., algorithm vulnerabilities) and update symfony/password-hasher proactively.
  • Adapter maintenance: Ensure the Laravel wrapper stays in sync with Symfony’s API changes (e.g., new algorithms, deprecations).
  • Algorithm support: Plan for end-of-life algorithms (e.g., bcrypt’s eventual phase-out in favor of Argon2).
  • Documentation: Maintain runbooks for:
    • Troubleshooting hash verification failures (e.g., malformed hashes).
    • Downgrading algorithms (e.g., reverting Argon2 to bcrypt).

Support:

  • Common issues:
    • Hash format errors: Users pasting plaintext passwords into hash fields.
    • Algorithm mismatches: Legacy systems expecting bcrypt but receiving Argon2.
    • Performance spikes: Argon2’s memory cost causing login delays.
  • Debugging tools:
    • Add a Hash::debug($hashedValue) method to inspect hash metadata (algorithm, parameters).
    • Log hash migration events (e.g., User hash upgraded from bcrypt to argon2id).
  • Team skills:
    • Requires security awareness to configure algorithms correctly (e.g., Argon2’s memory_cost).
    • May need database expertise to handle schema changes.

Scaling:

  • Horizontal scaling:
    • Hashing is CPU-bound (especially Argon2), so distribute load across servers.
    • Consider offloading hashing to
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport