Skip to content

Commit 1bdd1d8

Browse files
committed
Update recommended password encoder to "auto"
1 parent cbd36aa commit 1bdd1d8

File tree

5 files changed

+38
-41
lines changed

5 files changed

+38
-41
lines changed

best_practices/security.rst

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,17 @@ site (or maybe nearly *all* sections), use the ``access_control`` area.
2929

3030
.. best-practice::
3131

32-
Use the ``bcrypt`` encoder for hashing your users' passwords.
32+
Use the ``auto`` encoder for hashing your users' passwords.
3333

34-
If your users have a password, then we recommend hashing it using the ``bcrypt``
35-
encoder, instead of the traditional SHA-512 hashing encoder. The main advantages
36-
of ``bcrypt`` are the inclusion of a *salt* value to protect against rainbow
37-
table attacks, and its adaptive nature, which allows to make it slower to
38-
remain resistant to brute-force search attacks.
34+
If your users have a password, then we recommend hashing it using the ``auto``
35+
encoder, instead of the traditional SHA-512 or BCrypt hashing encoders. This configuration
36+
will ensure you use the best encoder available in your system.
3937

4038
.. note::
4139

4240
:ref:`Sodium <reference-security-sodium>` is the hashing algorithm as
4341
recommended by industry standards, but this won't be available to you unless
4442
you are using PHP 7.2+ or have the `libsodium`_ extension installed.
45-
``bcrypt`` is sufficient for most applications.
4643

4744
With this in mind, here is the authentication setup from our application,
4845
which uses a login form to load users from the database:
@@ -52,7 +49,7 @@ which uses a login form to load users from the database:
5249
# config/packages/security.yaml
5350
security:
5451
encoders:
55-
App\Entity\User: bcrypt
52+
App\Entity\User: auto
5653
5754
providers:
5855
database_users:

reference/configuration/security.rst

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,12 @@ encoding algorithm. Also, each algorithm defines different config options:
129129
# ...
130130
131131
encoders:
132-
# bcrypt encoder with default options
133-
App\Entity\User: 'bcrypt'
132+
# auto encoder with default options
133+
App\Entity\User: 'auto'
134134
135-
# bcrypt encoder with custom options
135+
# auto encoder with custom options
136136
App\Entity\User:
137-
algorithm: 'bcrypt'
137+
algorithm: 'auto'
138138
cost: 15
139139
140140
# Sodium encoder with default options
@@ -162,16 +162,16 @@ encoding algorithm. Also, each algorithm defines different config options:
162162
163163
<config>
164164
<!-- ... -->
165-
<!-- bcrypt encoder with default options -->
165+
<!-- auto encoder with default options -->
166166
<encoder
167167
class="App\Entity\User"
168-
algorithm="bcrypt"
168+
algorithm="auto"
169169
/>
170170
171-
<!-- bcrypt encoder with custom options -->
171+
<!-- auto encoder with custom options -->
172172
<encoder
173173
class="App\Entity\User"
174-
algorithm="bcrypt"
174+
algorithm="auto"
175175
cost="15"
176176
/>
177177
@@ -209,14 +209,14 @@ encoding algorithm. Also, each algorithm defines different config options:
209209
$container->loadFromExtension('security', [
210210
// ...
211211
'encoders' => [
212-
// bcrypt encoder with default options
212+
// auto encoder with default options
213213
User::class => [
214-
'algorithm' => 'bcrypt',
214+
'algorithm' => 'auto',
215215
],
216216
217-
// bcrypt encoder with custom options
217+
// auto encoder with custom options
218218
User::class => [
219-
'algorithm' => 'bcrypt',
219+
'algorithm' => 'auto',
220220
'cost' => 15,
221221
],
222222
@@ -280,12 +280,12 @@ password) so you don't have to deal with it.
280280

281281
.. _reference-security-bcrypt:
282282

283-
Using the BCrypt Password Encoder
283+
Using the "auto" Password Encoder
284284
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
285285

286-
It uses the `bcrypt password hashing function`_ and it's recommended to use it
287-
when it's not possible to use Sodium. The encoded passwords are ``60``
288-
characters long, so make sure to allocate enough space for them to be persisted.
286+
It uses Sodium as default, falling back to the `bcrypt password hashing function`_,
287+
which produces encoded passwords with ``60`` characters long, so make sure to allocate
288+
enough space for them to be persisted.
289289
Also, passwords include the `cryptographic salt`_ inside them (it's generated
290290
automatically for each new password) so you don't have to deal with it.
291291

@@ -311,7 +311,7 @@ Using the PBKDF2 Encoder
311311
~~~~~~~~~~~~~~~~~~~~~~~~
312312

313313
Using the `PBKDF2`_ encoder is no longer recommended since PHP added support for
314-
Sodium and bcrypt. Legacy application still using it are encouraged to upgrade
314+
Sodium and BCrypt. Legacy application still using it are encouraged to upgrade
315315
to those newer encoding algorithms.
316316

317317
firewalls

security.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,9 @@ command will pre-configure this for you:
124124
encoders:
125125
# use your user class name here
126126
App\Entity\User:
127-
# bcrypt or sodium are recommended
128-
# sodium is more secure, but requires PHP 7.2 or the Sodium extension
129-
algorithm: bcrypt
127+
# auto is recommended because it will try to use sodium, which
128+
# is more secure but requires PHP 7.2 or the Sodium extension
129+
algorithm: auto
130130
cost: 12
131131
132132
.. code-block:: xml
@@ -143,7 +143,7 @@ command will pre-configure this for you:
143143
<!-- ... -->
144144
145145
<encoder class="App\Entity\User"
146-
algorithm="bcrypt"
146+
algorithm="auto"
147147
cost="12"/>
148148
149149
<!-- ... -->
@@ -158,7 +158,7 @@ command will pre-configure this for you:
158158
159159
'encoders' => [
160160
'App\Entity\User' => [
161-
'algorithm' => 'bcrypt',
161+
'algorithm' => 'auto',
162162
'cost' => 12,
163163
]
164164
],

security/named_encoders.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ to apply to all instances of a specific class:
1616
# ...
1717
encoders:
1818
App\Entity\User:
19-
algorithm: bcrypt
19+
algorithm: auto
2020
cost: 12
2121
2222
.. code-block:: xml
@@ -32,7 +32,7 @@ to apply to all instances of a specific class:
3232
<config>
3333
<!-- ... -->
3434
<encoder class="App\Entity\User"
35-
algorithm="bcrypt"
35+
algorithm="auto"
3636
cost=12
3737
/>
3838
</config>
@@ -47,7 +47,7 @@ to apply to all instances of a specific class:
4747
// ...
4848
'encoders' => [
4949
User::class => [
50-
'algorithm' => 'bcrypt',
50+
'algorithm' => 'auto',
5151
'cost' => 12,
5252
],
5353
],
@@ -56,9 +56,9 @@ to apply to all instances of a specific class:
5656
Another option is to use a "named" encoder and then select which encoder
5757
you want to use dynamically.
5858

59-
In the previous example, you've set the ``bcrypt`` algorithm for ``App\Entity\User``.
59+
In the previous example, you've set the ``auto`` algorithm for ``App\Entity\User``.
6060
This may be secure enough for a regular user, but what if you want your admins
61-
to have a stronger algorithm, for example ``bcrypt`` with a higher cost. This can
61+
to have a stronger algorithm, for example ``auto`` with a higher cost. This can
6262
be done with named encoders:
6363

6464
.. configuration-block::
@@ -70,7 +70,7 @@ be done with named encoders:
7070
# ...
7171
encoders:
7272
harsh:
73-
algorithm: bcrypt
73+
algorithm: auto
7474
cost: 15
7575
7676
.. code-block:: xml
@@ -87,7 +87,7 @@ be done with named encoders:
8787
<config>
8888
<!-- ... -->
8989
<encoder class="harsh"
90-
algorithm="bcrypt"
90+
algorithm="auto"
9191
cost="15"/>
9292
</config>
9393
</srv:container>
@@ -99,7 +99,7 @@ be done with named encoders:
9999
// ...
100100
'encoders' => [
101101
'harsh' => [
102-
'algorithm' => 'bcrypt',
102+
'algorithm' => 'auto',
103103
'cost' => '15',
104104
],
105105
],

security/user_provider.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ users will encode their passwords:
224224
# ...
225225
encoders:
226226
# this internal class is used by Symfony to represent in-memory users
227-
Symfony\Component\Security\Core\User\User: 'bcrypt'
227+
Symfony\Component\Security\Core\User\User: 'auto'
228228
229229
.. code-block:: xml
230230
@@ -241,7 +241,7 @@ users will encode their passwords:
241241
242242
<!-- this internal class is used by Symfony to represent in-memory users -->
243243
<encoder class="Symfony\Component\Security\Core\User\User"
244-
algorithm="bcrypt"
244+
algorithm="auto"
245245
/>
246246
</config>
247247
</srv:container>
@@ -257,7 +257,7 @@ users will encode their passwords:
257257
// ...
258258
'encoders' => [
259259
User::class => [
260-
'algorithm' => 'bcrypt',
260+
'algorithm' => 'auto',
261261
],
262262
],
263263
]);

0 commit comments

Comments
 (0)