@@ -5,21 +5,20 @@ How to Migrate a Password Hash
5
5
==============================
6
6
7
7
In order to protect passwords, it is recommended to store them using the latest
8
- hash algorithms. This means that if a better hash algorithm is supported on the
9
- system, the user's password should be rehashed and stored. Symfony provides this
10
- functionality when a user is successfully authenticated.
11
-
12
- To enable this, make sure you apply the following steps to your application:
8
+ hash algorithms. This means that if a better hash algorithm is supported on your
9
+ system, the user's password should be *rehashed * using the newer algorithm and
10
+ stored. That's possible with the ``migrate_from `` option:
13
11
14
12
#. `Configure a new Encoder Using "migrate_from" `_
15
13
#. `Upgrade the Password `_
16
14
#. Optionally, `Trigger Password Migration From a Custom Encoder `_
17
15
18
16
Configure a new Encoder Using "migrate_from"
19
- --------------------------------------------
17
+ ----------------------------------------------
20
18
21
- When configuring a new encoder, you can specify a list of legacy encoders by
22
- using the ``migrate_from `` option:
19
+ When a better hashing algorithm becomes available, you should keep the existing
20
+ encoder(s), rename it, and then define the new one. Set the ``migrate_from `` option
21
+ on the new encoder to point to the old, legacy encoder(s):
23
22
24
23
.. configuration-block ::
25
24
@@ -30,6 +29,7 @@ using the ``migrate_from`` option:
30
29
# ...
31
30
32
31
encoders :
32
+ # an encoder used in the past for some users
33
33
legacy :
34
34
algorithm : sha256
35
35
encode_as_base64 : false
@@ -98,6 +98,13 @@ using the ``migrate_from`` option:
98
98
],
99
99
]);
100
100
101
+ With this setup:
102
+
103
+ * New users will be encoded with the new algorithm;
104
+ * Whenever a user logs in whose password is still stored using the old algorithm,
105
+ Symfony will verify the password with the old algorithm and then rehash
106
+ and update the password using the new algorithm.
107
+
101
108
.. tip ::
102
109
103
110
The *auto *, *native *, *bcrypt * and *argon * encoders automatically enable
@@ -106,7 +113,7 @@ using the ``migrate_from`` option:
106
113
#. :ref: `PBKDF2 <reference-security-pbkdf2 >` (which uses :phpfunction: `hash_pbkdf2 `);
107
114
#. Message digest (which uses :phpfunction: `hash `)
108
115
109
- Both use the ``hash_algorithm `` setting as algorithm. It is recommended to
116
+ Both use the ``hash_algorithm `` setting as the algorithm. It is recommended to
110
117
use ``migrate_from `` instead of ``hash_algorithm ``, unless the *auto *
111
118
encoder is used.
112
119
0 commit comments