Skip to content

Commit 2dfbadb

Browse files
committed
Merge branch '4.3' into 4.4
* 4.3: Update recommended password encoder to \"auto\"
2 parents 4279ba8 + 44c434c commit 2dfbadb

File tree

5 files changed

+41
-43
lines changed

5 files changed

+41
-43
lines changed

best_practices/security.rst

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,13 @@ 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.
33-
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.
32+
Use the ``auto`` encoder for hashing your users' passwords.
3933

4034
.. note::
4135

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

4740
With this in mind, here is the authentication setup from our application,
4841
which uses a login form to load users from the database:
@@ -52,7 +45,7 @@ which uses a login form to load users from the database:
5245
# config/packages/security.yaml
5346
security:
5447
encoders:
55-
App\Entity\User: bcrypt
48+
App\Entity\User: auto
5649
5750
providers:
5851
database_users:

reference/configuration/security.rst

Lines changed: 24 additions & 20 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
@@ -278,16 +278,20 @@ sure to allocate enough space for them to be persisted. Also, passwords include
278278
the `cryptographic salt`_ inside them (it's generated automatically for each new
279279
password) so you don't have to deal with it.
280280

281-
.. _reference-security-bcrypt:
281+
.. _reference-security-encoder-auto:
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.
289-
Also, passwords include the `cryptographic salt`_ inside them (it's generated
290-
automatically for each new password) so you don't have to deal with it.
286+
It selects automatically the best possible encoder. Currently, it tries to use
287+
Sodium by default and falls back to the `bcrypt password hashing function`_ if
288+
not possible. In the future, when PHP adds new hashing techniques, it may use
289+
different password hashers.
290+
291+
It produces encoded passwords with ``60`` characters long, so make sure to
292+
allocate enough space for them to be persisted. Also, passwords include the
293+
`cryptographic salt`_ inside them (it's generated automatically for each new
294+
password) so you don't have to deal with it.
291295

292296
Its only configuration option is ``cost``, which is an integer in the range of
293297
``4-31`` (by default, ``13``). Each single increment of the cost **doubles the
@@ -311,7 +315,7 @@ Using the PBKDF2 Encoder
311315
~~~~~~~~~~~~~~~~~~~~~~~~
312316

313317
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
318+
Sodium and BCrypt. Legacy application still using it are encouraged to upgrade
315319
to those newer encoding algorithms.
316320

317321
firewalls

security.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ command will pre-configure this for you:
125125
# use your user class name here
126126
App\Entity\User:
127127
# Use native password encoder
128-
# This value auto-selects the best possible hashing algorithm.
128+
# This value auto-selects the best possible hashing algorithm
129+
# (i.e. Sodium when available).
129130
algorithm: auto
130131
131132
.. code-block:: xml
@@ -142,7 +143,7 @@ command will pre-configure this for you:
142143
<!-- ... -->
143144
144145
<encoder class="App\Entity\User"
145-
algorithm="bcrypt"
146+
algorithm="auto"
146147
cost="12"/>
147148
148149
<!-- ... -->
@@ -157,7 +158,7 @@ command will pre-configure this for you:
157158
158159
'encoders' => [
159160
'App\Entity\User' => [
160-
'algorithm' => 'bcrypt',
161+
'algorithm' => 'auto',
161162
'cost' => 12,
162163
]
163164
],

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)