Skip to content

Commit ae8bac8

Browse files
Merge branch '6.2' into 6.3
* 6.2: [Translation] Fix merge [SecurityBundle] Fix `Security::login()` on specific firewall [MonologBridge] FirePHPHandler::onKernelResponse throws PHP 8.1 deprecation when no user agent is set [Form] Skip password hashing on empty password Update Redis version to 6.2.8 [Contracts] Fix setting $container before calling parent::setContainer in ServiceSubscriberTrait [Messenger][Cache] fixed CallbackInterface support in async expiration handler do not drop embed label classes
2 parents 79002e4 + f491e48 commit ae8bac8

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

Extension/PasswordHasher/EventListener/PasswordHasherListener.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ public function __construct(
4040
*/
4141
public function registerPassword(FormEvent $event)
4242
{
43+
if (null === $event->getData() || '' === $event->getData()) {
44+
return;
45+
}
46+
4347
$this->assertNotMapped($event->getForm());
4448

4549
$this->passwords[] = [

Tests/Extension/PasswordHasher/Type/PasswordTypePasswordHasherExtensionTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use PHPUnit\Framework\MockObject\MockObject;
1515
use Symfony\Component\Form\Exception\InvalidConfigurationException;
16+
use Symfony\Component\Form\Extension\Core\Type\FormType;
1617
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
1718
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
1819
use Symfony\Component\Form\Extension\PasswordHasher\EventListener\PasswordHasherListener;
@@ -80,6 +81,36 @@ public function testPasswordHashSuccess()
8081
$this->assertSame($user->getPassword(), $hashedPassword);
8182
}
8283

84+
public function testPasswordHashSkippedWithEmptyPassword()
85+
{
86+
$oldHashedPassword = 'PreviousHashedPassword';
87+
88+
$user = new User();
89+
$user->setPassword($oldHashedPassword);
90+
91+
$this->passwordHasher
92+
->expects($this->never())
93+
->method('hashPassword')
94+
;
95+
96+
$this->assertEquals($user->getPassword(), $oldHashedPassword);
97+
98+
$form = $this->factory
99+
->createBuilder(FormType::class, $user)
100+
->add('plainPassword', PasswordType::class, [
101+
'hash_property_path' => 'password',
102+
'mapped' => false,
103+
'required' => false,
104+
])
105+
->getForm()
106+
;
107+
108+
$form->submit(['plainPassword' => '']);
109+
110+
$this->assertTrue($form->isValid());
111+
$this->assertSame($user->getPassword(), $oldHashedPassword);
112+
}
113+
83114
public function testPasswordHashSuccessWithEmptyData()
84115
{
85116
$user = new User();

0 commit comments

Comments
 (0)