Skip to content

Commit ad254ad

Browse files
committed
[Form] Add hash_mapping option to PasswordType
1 parent f44888a commit ad254ad

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

DependencyInjection/SecurityExtension.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
use Symfony\Component\EventDispatcher\EventDispatcher;
3434
use Symfony\Component\ExpressionLanguage\Expression;
3535
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
36+
use Symfony\Component\Form\Extension\PasswordHasher\PasswordHasherExtension;
3637
use Symfony\Component\HttpFoundation\ChainRequestMatcher;
3738
use Symfony\Component\HttpFoundation\RequestMatcher\AttributesRequestMatcher;
3839
use Symfony\Component\HttpFoundation\RequestMatcher\HostRequestMatcher;
@@ -124,6 +125,12 @@ public function load(array $configs, ContainerBuilder $container)
124125
$container->removeDefinition('security.is_granted_attribute_expression_language');
125126
}
126127

128+
if (!class_exists(PasswordHasherExtension::class)) {
129+
$container->removeDefinition('form.listener.password_hasher');
130+
$container->removeDefinition('form.type_extension.form.password_hasher');
131+
$container->removeDefinition('form.type_extension.password.password_hasher');
132+
}
133+
127134
// set some global scalars
128135
$container->setParameter('security.access.denied_url', $config['access_denied_url']);
129136
$container->setParameter('security.authentication.manager.erase_credentials', $config['erase_credentials']);

Resources/config/password_hasher.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111

1212
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
1313

14+
use Symfony\Component\Form\Extension\Core\Type\FormType;
15+
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
16+
use Symfony\Component\Form\Extension\PasswordHasher\EventListener\PasswordHasherListener;
17+
use Symfony\Component\Form\Extension\PasswordHasher\Type\FormTypePasswordHasherExtension;
18+
use Symfony\Component\Form\Extension\PasswordHasher\Type\PasswordTypePasswordHasherExtension;
1419
use Symfony\Component\PasswordHasher\Hasher\PasswordHasherFactory;
1520
use Symfony\Component\PasswordHasher\Hasher\PasswordHasherFactoryInterface;
1621
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasher;
@@ -26,5 +31,23 @@
2631
->args([service('security.password_hasher_factory')])
2732
->alias('security.password_hasher', 'security.user_password_hasher')
2833
->alias(UserPasswordHasherInterface::class, 'security.password_hasher')
34+
35+
->set('form.listener.password_hasher', PasswordHasherListener::class)
36+
->args([
37+
service('security.password_hasher'),
38+
service('property_accessor')->nullOnInvalid(),
39+
])
40+
41+
->set('form.type_extension.form.password_hasher', FormTypePasswordHasherExtension::class)
42+
->args([
43+
service('form.listener.password_hasher'),
44+
])
45+
->tag('form.type_extension', ['extended-type' => FormType::class])
46+
47+
->set('form.type_extension.password.password_hasher', PasswordTypePasswordHasherExtension::class)
48+
->args([
49+
service('form.listener.password_hasher'),
50+
])
51+
->tag('form.type_extension', ['extended-type' => PasswordType::class])
2952
;
3053
};

0 commit comments

Comments
 (0)