symfony/password-hasher
Symfony PasswordHasher provides secure password hashing and verification with modern algorithms like bcrypt and sodium. Use PasswordHasherFactory to configure multiple hashers and select the right one for your app’s needs.
Hash facade and Illuminate\Auth\Passwords\PasswordBroker with zero breaking changes to existing authentication flows. Leverages Laravel’s service container for dependency injection, ensuring compatibility with Fortify, Sanctum, Passport, and custom auth systems.PasswordHasherFactory abstracts hashing logic, allowing dynamic algorithm selection (e.g., bcrypt for standard users, Argon2id for admins) via configuration. This aligns with Laravel’s modularity and Symfony’s component-based architecture, enabling gradual security upgrades.PasswordHasherInterface, allowing integration with third-party algorithms (e.g., scrypt) or internal security policies (e.g., per-tenant hashing rules).Hash facade can be swapped atomically with minimal code changes.Hash::make()) remain valid, reducing migration risk. Legacy hashes (e.g., SHA-1) can be gradually rehashed on login.PasswordHasherFactory, enabling environment-specific hashing (e.g., Argon2id in staging, bcrypt in production).make:auth), Tinker, and debugbar for seamless development and troubleshooting.Hash service or extend the PasswordHasherFactory.Algorithm Selection:
Migration Strategy:
Compatibility:
Hash facade? How will we test integration?Monitoring and Alerts:
Future-Proofing:
Hash facade, Illuminate\Auth, and Laravel Breeze/Fortify. No need for polyfills or shims.security:hash-password command.Hash facade internally.password_hash(), Hash::make()).composer require symfony/password-hasher
Hash Service (config/app.php):
'hash' => [
'driver' => Symfony\Component\PasswordHasher\Hasher\PasswordHasherFactory::class,
'config' => [
'default' => ['algorithm' => 'bcrypt'],
'admin' => ['algorithm' => 'argon2id'],
],
],
AuthServiceProvider (if using custom hashing):
public function boot()
{
$this->app['hash'] = $this->app->extend('hash', function ($hash, $app) {
return new PasswordHasherFactory($app['config']['hash.config']);
});
}
Illuminate\Auth\Events\Attempting to rehash legacy hashes:
event(new Attempting($credentials));
// In listener:
if (str_starts_with($user->password, '$2y$')) { // bcrypt
return;
}
$user->password = $factory->getPasswordHasher('default')->hash($credentials['password']);
$user->save();
// Command: php artisan rehash:legacy
RehashLegacyHashes::dispatch();
class RehashLegacyHashes implements ShouldQueue
{
public function handle()
{
User::where('password', 'like', '%$2a$%') // SHA-1/MD5
->chunk(100, function ($users) {
$factory = app(PasswordHasherFactory::class);
foreach ($users as $user) {
$user->password = $factory->getPasswordHasher('default')->hash($user->password);
}
User::upsert($users->toArray());
});
}
}
PasswordHasherFactory integration with:
Hash::make() and Hash::check().| Component | Compatibility Status | Notes |
|---|---|---|
| Laravel 8.x–10.x | ✅ Full | Uses Symfony 6.x/7.x/8.x under the hood. |
| Lumen 8.x–9 |
How can I help you explore Laravel packages today?