samasend/laravel-needs-auto-rehash
Laravel Needs Auto Rehash automatically detects outdated password hashes and rehashes them after successful login, keeping user credentials aligned with your app’s current hashing algorithm and cost settings with minimal configuration.
Hash::needsRehash($user->password) and, if true, writes back Hash::make($plaintext). That is roughly 10–15 lines plus tests. The package is archived, last released 2023-02-20, 66 stars, single maintainer. For a security-relevant path, this supports the decision to build in-house and use the package only as a reference implementation.bcrypt rounds (e.g., 10 → 12) or migrating drivers (bcrypt → argon2id) normally implies a forced password-reset campaign or a long-running "rehash on login" project. With this pattern, raising the cost factor becomes a one-line config change; the user population self-migrates over the following weeks of normal logins. That turns a multi-sprint migration item into a config ticket.Hash::make on a new password). Framing it as a single-purpose migration accelerator keeps scope honest.Consider the pattern (and read this package's source) when:
Hash driver or raising bcrypt rounds in config/hashing.php.Look elsewhere — or just write it yourself — when:
EventListener bound to the login event, plus a feature test. You inherit no maintenance risk and control the semantics (logging, queueing, notifications).To executives (one paragraph): Password hashing strength decays as hardware gets faster, and industry guidance says we should upgrade stored hashes when our cost settings change. Normally that means forcing every user through a password reset — a support and churn event. There's a well-known pattern that upgrades each user's hash silently at their next successful login, so we get stronger security with zero user friction and no reset campaign. The specific open-source package that implements it is tiny and no longer maintained, so the recommendation is to adopt the pattern, not the dependency: a small, tested listener of our own, roughly a day of engineering including tests. Net effect: better security posture, lower migration risk, no user-facing change.
To engineering: Add a listener on the successful-login event that calls Hash::needsRehash($user->password) and, when true, persists Hash::make() of the just-validated plaintext. Requirements: fire only after authentication succeeds; suppress password-changed notifications and remember-token invalidation; avoid re-hashing on every request; log a counter/metric rather than the value; make the write idempotent and consider queuing it if a cost-factor bump would otherwise spike database writes across the user base. Sequence the rollout as ship listener → observe → raise bcrypt cost or switch driver → monitor the rehash metric until it flattens. Do not take a dependency on an archived 2023 package for this; copy the ~10 lines, credit the source, and add the tests it never had.
How can I help you explore Laravel packages today?