@@ -2779,22 +2779,21 @@ object) are "compared" to see if they are "equal". By default, the core
2779
2779
your user will be logged out. This is a security measure to make sure that malicious
2780
2780
users can be de-authenticated if core user data changes.
2781
2781
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 ``::
2782
+ Storing the (plain or hashed) password in the session can be a security risk.
2783
+ To mitigate this, implement the ``__serialize() `` magic method in your user class
2784
+ to exclude or transform the password before storing the serialized user object
2785
+ in the session.
2786
+
2787
+ Two strategies are supported:
2788
+
2789
+ #. Remove the password completely. After unserialization, ``getPassword() `` returns
2790
+ ``null `` and Symfony refreshes the user without checking the password. Use this
2791
+ only if you store plaintext passwords (not recommended).
2792
+ #. Hash the password using the ``crc32c `` algorithm. Symfony will hash the password
2793
+ of the refreshed user and compare it to the session value. This approach avoids
2794
+ storing the real hash and lets you invalidate sessions on password change.
2795
+
2796
+ Example (assuming the password is stored in a private property called ``password ``)::
2798
2797
2799
2798
public function __serialize(): array
2800
2799
{
@@ -2804,6 +2803,11 @@ Two strategies are supported while serializing:
2804
2803
return $data;
2805
2804
}
2806
2805
2806
+ .. versionadded :: 7.3
2807
+
2808
+ Support for hashing passwords with ``crc32c `` in session serialization was
2809
+ introduced in Symfony 7.3.
2810
+
2807
2811
If you're having problems authenticating, it could be that you *are * authenticating
2808
2812
successfully, but you immediately lose authentication after the first redirect.
2809
2813
0 commit comments