@@ -9,21 +9,20 @@ How to Migrate a Password Hash
99 Password migration was introduced in Symfony 4.4.
1010
1111In order to protect passwords, it is recommended to store them using the latest
12- hash algorithms. This means that if a better hash algorithm is supported on the
13- system, the user's password should be rehashed and stored. Symfony provides this
14- functionality when a user is successfully authenticated.
15-
16- To enable this, make sure you apply the following steps to your application:
12+ hash algorithms. This means that if a better hash algorithm is supported on your
13+ system, the user's password should be *rehashed * using the newer algorithm and
14+ stored. That's possible with the ``migrate_from `` option:
1715
1816#. `Configure a new Encoder Using "migrate_from" `_
1917#. `Upgrade the Password `_
2018#. Optionally, `Trigger Password Migration From a Custom Encoder `_
2119
2220Configure a new Encoder Using "migrate_from"
23- --------------------------------------------
21+ ----------------------------------------------
2422
25- When configuring a new encoder, you can specify a list of legacy encoders by
26- using the ``migrate_from `` option:
23+ When a better hashing algorithm becomes available, you should keep the existing
24+ encoder(s), rename it, and then define the new one. Set the ``migrate_from `` option
25+ on the new encoder to point to the old, legacy encoder(s):
2726
2827.. configuration-block ::
2928
@@ -34,6 +33,7 @@ using the ``migrate_from`` option:
3433 # ...
3534
3635 encoders :
36+ # an encoder used in the past for some users
3737 legacy :
3838 algorithm : sha256
3939 encode_as_base64 : false
@@ -102,6 +102,13 @@ using the ``migrate_from`` option:
102102 ],
103103 ]);
104104
105+ With this setup:
106+
107+ * New users will be encoded with the new algorithm;
108+ * Whenever a user logs in whose password is still stored using the old algorithm,
109+ Symfony will verify the password with the old algorithm and then re-encode
110+ and update the hashed password using the new algorithm.
111+
105112.. tip ::
106113
107114 The *auto *, *native *, *bcrypt * and *argon * encoders automatically enable
@@ -110,7 +117,7 @@ using the ``migrate_from`` option:
110117 #. :ref: `PBKDF2 <reference-security-pbkdf2 >` (which uses :phpfunction: `hash_pbkdf2 `);
111118 #. Message digest (which uses :phpfunction: `hash `)
112119
113- Both use the ``hash_algorithm `` setting as algorithm. It is recommended to
120+ Both use the ``hash_algorithm `` setting as the algorithm. It is recommended to
114121 use ``migrate_from `` instead of ``hash_algorithm ``, unless the *auto *
115122 encoder is used.
116123
0 commit comments