Skip to content

Commit 4ba90e1

Browse files
committed
do not implement __serialize() for users without passwords
1 parent c86da84 commit 4ba90e1

File tree

3 files changed

+1
-23
lines changed

3 files changed

+1
-23
lines changed

src/Security/UserClassBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function addUserInterfaceImplementation(ClassSourceManipulator $manipulat
3838

3939
$this->addPasswordImplementation($manipulator, $userClassConfig);
4040

41-
if (class_exists(IsGrantedContext::class)) {
41+
if (class_exists(IsGrantedContext::class) && $userClassConfig->hasPassword()) {
4242
$this->addSerialize($manipulator);
4343
}
4444

tests/Security/fixtures/expected/UserEntityWithoutPassword.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,6 @@ public function setRoles(array $roles): static
6767
return $this;
6868
}
6969

70-
/**
71-
* Ensure the session doesn't contain actual password hashes by CRC32C-hashing them, as supported since Symfony 7.3.
72-
*/
73-
public function __serialize(): array
74-
{
75-
$data = (array) $this;
76-
$data["\0" . self::class . "\0password"] = hash('crc32c', $this->password);
77-
78-
return $data;
79-
}
80-
8170
#[\Deprecated]
8271
public function eraseCredentials(): void
8372
{

tests/Security/fixtures/expected/UserModelWithoutPassword.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,6 @@ public function setRoles(array $roles): static
5252
return $this;
5353
}
5454

55-
/**
56-
* Ensure the session doesn't contain actual password hashes by CRC32C-hashing them, as supported since Symfony 7.3.
57-
*/
58-
public function __serialize(): array
59-
{
60-
$data = (array) $this;
61-
$data["\0" . self::class . "\0password"] = hash('crc32c', $this->password);
62-
63-
return $data;
64-
}
65-
6655
#[\Deprecated]
6756
public function eraseCredentials(): void
6857
{

0 commit comments

Comments
 (0)