@@ -193,14 +193,7 @@ from the `MakerBundle`_:
193193 return $this;
194194 }
195195
196- /**
197- * @see UserInterface
198- */
199- public function eraseCredentials(): void
200- {
201- // If you store any temporary, sensitive data on the user, clear it here
202- // $this->plainPassword = null;
203- }
196+ // [...]
204197 }
205198
206199 .. tip ::
@@ -2786,7 +2779,33 @@ object) are "compared" to see if they are "equal". By default, the core
27862779your user will be logged out. This is a security measure to make sure that malicious
27872780users can be de-authenticated if core user data changes.
27882781
2789- However, in some cases, this process can cause unexpected authentication problems.
2782+ Note that storing the (plain or hashed) password in the session storage can be seen
2783+ as a security risk. In order to address this risk, the ``__serialize() `` magic method
2784+ can be implemented on the user class to filter out the password before storing the
2785+ serialized user object in the session.
2786+ Two strategies are supported while serializing:
2787+
2788+ #. Removing the password entirely. In this case, ``getPassword() `` will return ``null ``
2789+ after unserialization and Symfony will refresh the user without checking the
2790+ password. Use this strategy if you store plaintext passwords (not recommended.)
2791+ #. Hashing the password using the ``crc32c `` algorithm. In this case Symfony will
2792+ compare the password of the refreshed user after crc32c-hashing it. This is a good
2793+ strategy if you use hashed passwords since it allows invalidating concurrent
2794+ sessions when a password changes without storing the password hash in the session.
2795+
2796+ Here is an example of how to implement this, assuming the password is found in a
2797+ private property named ``password ``:
2798+
2799+ .. code-block :: php
2800+
2801+ public function __serialize(): array
2802+ {
2803+ $data = (array) $this;
2804+ $data["\0".self::class."\0password"] = hash('crc32c', $this->password);
2805+
2806+ return $data;
2807+ }
2808+
27902809 If you're having problems authenticating, it could be that you *are * authenticating
27912810successfully, but you immediately lose authentication after the first redirect.
27922811
0 commit comments