@@ -40,7 +40,7 @@ Some of these options define tens of sub-options and they are explained in
40
40
separate articles:
41
41
42
42
* `access_control `_
43
- * `encoders `_
43
+ * `hashers `_
44
44
* `firewalls `_
45
45
* `providers `_
46
46
* `role_hierarchy `_
@@ -120,15 +120,16 @@ and to allow anonymous users to the login form page.
120
120
121
121
This option is explained in detail in :doc: `/security/access_control `.
122
122
123
- encoders
124
- --------
123
+ .. _encoders :
125
124
126
- This option defines the algorithm used to *encode * the password of the users.
127
- Although Symfony calls it *"password encoding" * for historical reasons, this is
128
- in fact, *"password hashing" *.
125
+ hashers
126
+ -------
127
+
128
+ This option defines the algorithm used to *hash * the password of the users
129
+ (which in previous Symfony versions was wrongly called *"password encoding" *).
129
130
130
131
If your app defines more than one user class, each of them can define its own
131
- encoding algorithm. Also, each algorithm defines different config options:
132
+ hashing algorithm. Also, each algorithm defines different config options:
132
133
133
134
.. configuration-block ::
134
135
@@ -138,25 +139,25 @@ encoding algorithm. Also, each algorithm defines different config options:
138
139
security :
139
140
# ...
140
141
141
- encoders :
142
- # auto encoder with default options
142
+ password_hashers :
143
+ # auto hasher with default options
143
144
App\Entity\User : ' auto'
144
145
145
- # auto encoder with custom options
146
+ # auto hasher with custom options
146
147
App\Entity\User :
147
148
algorithm : ' auto'
148
149
cost : 15
149
150
150
- # Sodium encoder with default options
151
+ # Sodium hasher with default options
151
152
App\Entity\User : ' sodium'
152
153
153
- # Sodium encoder with custom options
154
+ # Sodium hasher with custom options
154
155
App\Entity\User :
155
156
algorithm : ' sodium'
156
157
memory_cost : 16384 # Amount in KiB. (16384 = 16 MiB)
157
158
time_cost : 2 # Number of iterations
158
159
159
- # MessageDigestPasswordEncoder encoder using SHA512 hashing with default options
160
+ # MessageDigestPasswordHasher hasher using SHA512 hashing with default options
160
161
App\Entity\User : ' sha512'
161
162
162
163
.. code-block :: xml
@@ -173,37 +174,37 @@ encoding algorithm. Also, each algorithm defines different config options:
173
174
174
175
<config >
175
176
<!-- ... -->
176
- <!-- auto encoder with default options -->
177
- <encoder
177
+ <!-- auto hasher with default options -->
178
+ <security : password-hasher
178
179
class =" App\Entity\User"
179
180
algorithm =" auto"
180
181
/>
181
182
182
- <!-- auto encoder with custom options -->
183
- <encoder
183
+ <!-- auto hasher with custom options -->
184
+ <security : password-hasher
184
185
class =" App\Entity\User"
185
186
algorithm =" auto"
186
187
cost =" 15"
187
188
/>
188
189
189
- <!-- Sodium encoder with default options -->
190
- <encoder
190
+ <!-- Sodium hasher with default options -->
191
+ <security : password-hasher
191
192
class =" App\Entity\User"
192
193
algorithm =" sodium"
193
194
/>
194
195
195
- <!-- Sodium encoder with custom options -->
196
+ <!-- Sodium hasher with custom options -->
196
197
<!-- memory_cost: amount in KiB. (16384 = 16 MiB)
197
198
time_cost: number of iterations -->
198
- <encoder
199
+ <security : password-hasher
199
200
class =" App\Entity\User"
200
201
algorithm =" sodium"
201
202
memory_cost =" 16384"
202
203
time_cost =" 2"
203
204
/>
204
205
205
- <!-- MessageDigestPasswordEncoder encoder using SHA512 hashing with default options -->
206
- <encoder
206
+ <!-- MessageDigestPasswordHasher hasher using SHA512 hashing with default options -->
207
+ <security : password-hasher
207
208
class =" App\Entity\User"
208
209
algorithm =" sha512"
209
210
/>
@@ -217,55 +218,61 @@ encoding algorithm. Also, each algorithm defines different config options:
217
218
218
219
$container->loadFromExtension('security', [
219
220
// ...
220
- 'encoders ' => [
221
- // auto encoder with default options
221
+ 'password_hashers ' => [
222
+ // auto hasher with default options
222
223
User::class => [
223
224
'algorithm' => 'auto',
224
225
],
225
226
226
- // auto encoder with custom options
227
+ // auto hasher with custom options
227
228
User::class => [
228
229
'algorithm' => 'auto',
229
230
'cost' => 15,
230
231
],
231
232
232
- // Sodium encoder with default options
233
+ // Sodium hasher with default options
233
234
User::class => [
234
235
'algorithm' => 'sodium',
235
236
],
236
237
237
- // Sodium encoder with custom options
238
+ // Sodium hasher with custom options
238
239
User::class => [
239
240
'algorithm' => 'sodium',
240
241
'memory_cost' => 16384, // Amount in KiB. (16384 = 16 MiB)
241
242
'time_cost' => 2, // Number of iterations
242
243
],
243
244
244
- // MessageDigestPasswordEncoder encoder using SHA512 hashing with default options
245
+ // MessageDigestPasswordHasher hasher using SHA512 hashing with default options
245
246
User::class => [
246
247
'algorithm' => 'sha512',
247
248
],
248
249
],
249
250
]);
250
251
252
+ .. versionadded :: 5.3
253
+
254
+ The ``password_hashers `` option was introduced in Symfony 5.3. In previous
255
+ versions it was called ``encoders ``.
256
+
251
257
.. tip ::
252
258
253
- You can also create your own password encoders as services and you can even
254
- select a different password encoder for each user instance. Read
259
+ You can also create your own password hashers as services and you can even
260
+ select a different password hasher for each user instance. Read
255
261
:doc: `this article </security/named_encoders >` for more details.
256
262
257
263
.. tip ::
258
264
259
- Encoding passwords is resource intensive and takes time in order to generate
265
+ Hashing passwords is resource intensive and takes time in order to generate
260
266
secure password hashes. In tests however, secure hashes are not important, so
261
- you can change the encoders configuration in ``test `` environment to run tests faster:
267
+ you can change the password hasher configuration in ``test `` environment to
268
+ run tests faster:
262
269
263
270
.. configuration-block ::
264
271
265
272
.. code-block :: yaml
266
273
267
274
# config/packages/test/security.yaml
268
- encoders :
275
+ password_hashers :
269
276
# Use your user class name here
270
277
App\Entity\User :
271
278
algorithm : auto # This should be the same value as in config/packages/security.yaml
@@ -289,7 +296,7 @@ encoding algorithm. Also, each algorithm defines different config options:
289
296
<!-- cost: Lowest possible value for bcrypt -->
290
297
<!-- time_cost: Lowest possible value for argon -->
291
298
<!-- memory_cost: Lowest possible value for argon -->
292
- <encoder
299
+ <security : password-hasher
293
300
class =" App\Entity\User"
294
301
algorithm =" auto"
295
302
cost =" 4"
@@ -305,7 +312,7 @@ encoding algorithm. Also, each algorithm defines different config options:
305
312
use App\Entity\User;
306
313
307
314
$container->loadFromExtension('security', [
308
- 'encoders ' => [
315
+ 'password_hashers ' => [
309
316
// Use your user class name here
310
317
User::class => [
311
318
'algorithm' => 'auto', // This should be the same value as in config/packages/security.yaml
@@ -318,44 +325,46 @@ encoding algorithm. Also, each algorithm defines different config options:
318
325
319
326
.. _reference-security-sodium :
320
327
.. _using-the-argon2i-password-encoder :
328
+ .. _using-the-sodium-password-encoder :
321
329
322
- Using the Sodium Password Encoder
323
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
330
+ Using the Sodium Password Hasher
331
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
324
332
325
- It uses the `Argon2 key derivation function `_ and it's the encoder recommended
333
+ It uses the `Argon2 key derivation function `_ and it's the hasher recommended
326
334
by Symfony. Argon2 support was introduced in PHP 7.2, but if you use an earlier
327
335
PHP version, you can install the `libsodium `_ PHP extension.
328
336
329
- The encoded passwords are ``96 `` characters long, but due to the hashing
337
+ The hashed passwords are ``96 `` characters long, but due to the hashing
330
338
requirements saved in the resulting hash this may change in the future, so make
331
339
sure to allocate enough space for them to be persisted. Also, passwords include
332
340
the `cryptographic salt `_ inside them (it's generated automatically for each new
333
341
password) so you don't have to deal with it.
334
342
335
343
.. _reference-security-encoder-auto :
344
+ .. _using-the-auto-password-encoder :
336
345
337
- Using the "auto" Password Encoder
338
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
346
+ Using the "auto" Password Hasher
347
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
339
348
340
- It selects automatically the best possible encoder . Currently, it tries to use
349
+ It selects automatically the best possible hasher . Currently, it tries to use
341
350
Sodium by default and falls back to the `bcrypt password hashing function `_ if
342
351
not possible. In the future, when PHP adds new hashing techniques, it may use
343
352
different password hashers.
344
353
345
- It produces encoded passwords with ``60 `` characters long, so make sure to
354
+ It produces hashed passwords with ``60 `` characters long, so make sure to
346
355
allocate enough space for them to be persisted. Also, passwords include the
347
356
`cryptographic salt `_ inside them (it's generated automatically for each new
348
357
password) so you don't have to deal with it.
349
358
350
359
Its only configuration option is ``cost ``, which is an integer in the range of
351
360
``4-31 `` (by default, ``13 ``). Each single increment of the cost **doubles the
352
- time ** it takes to encode a password. It's designed this way so the password
361
+ time ** it takes to hash a password. It's designed this way so the password
353
362
strength can be adapted to the future improvements in computation power.
354
363
355
364
You can change the cost at any time — even if you already have some passwords
356
- encoded using a different cost. New passwords will be encoded using the new
357
- cost, while the already encoded ones will be validated using a cost that was
358
- used back when they were encoded .
365
+ hashed using a different cost. New passwords will be hashed using the new
366
+ cost, while the already hashed ones will be validated using a cost that was
367
+ used back when they were hashed .
359
368
360
369
.. tip ::
361
370
@@ -364,13 +373,14 @@ used back when they were encoded.
364
373
environment configuration.
365
374
366
375
.. _reference-security-pbkdf2 :
376
+ .. _using-the-pbkdf2-encoder :
367
377
368
- Using the PBKDF2 Encoder
369
- ~~~~~~~~~~~~~~~~~~~~~~~~
378
+ Using the PBKDF2 Hasher
379
+ ~~~~~~~~~~~~~~~~~~~~~~~
370
380
371
- Using the `PBKDF2 `_ encoder is no longer recommended since PHP added support for
381
+ Using the `PBKDF2 `_ hasher is no longer recommended since PHP added support for
372
382
Sodium and BCrypt. Legacy application still using it are encouraged to upgrade
373
- to those newer encoding algorithms.
383
+ to those newer hashing algorithms.
374
384
375
385
firewalls
376
386
---------
0 commit comments