@@ -9,21 +9,20 @@ How to Migrate a Password Hash
9
9
Password migration was introduced in Symfony 4.4.
10
10
11
11
In 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:
17
15
18
16
#. `Configure a new Encoder Using "migrate_from" `_
19
17
#. `Upgrade the Password `_
20
18
#. Optionally, `Trigger Password Migration From a Custom Encoder `_
21
19
22
20
Configure a new Encoder Using "migrate_from"
23
- --------------------------------------------
21
+ ----------------------------------------------
24
22
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):
27
26
28
27
.. configuration-block ::
29
28
@@ -34,6 +33,7 @@ using the ``migrate_from`` option:
34
33
# ...
35
34
36
35
encoders :
36
+ # an encoder used in the past for some users
37
37
legacy :
38
38
algorithm : sha256
39
39
encode_as_base64 : false
@@ -102,6 +102,13 @@ using the ``migrate_from`` option:
102
102
],
103
103
]);
104
104
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
+
105
112
.. tip ::
106
113
107
114
The *auto *, *native *, *bcrypt * and *argon * encoders automatically enable
@@ -110,7 +117,7 @@ using the ``migrate_from`` option:
110
117
#. :ref: `PBKDF2 <reference-security-pbkdf2 >` (which uses :phpfunction: `hash_pbkdf2 `);
111
118
#. Message digest (which uses :phpfunction: `hash `)
112
119
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
114
121
use ``migrate_from `` instead of ``hash_algorithm ``, unless the *auto *
115
122
encoder is used.
116
123
0 commit comments