Skip to content

Commit e31bd1d

Browse files
committed
Updated another article
1 parent 06d29f7 commit e31bd1d

File tree

2 files changed

+34
-33
lines changed

2 files changed

+34
-33
lines changed

_build/redirection_map

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,3 +514,4 @@
514514
/service_container/3.3-di-changes https://symfony.com/doc/3.4/service_container/3.3-di-changes.html
515515
/frontend/encore/shared-entry /frontend/encore/split-chunks
516516
/testing/functional_tests_assertions /testing#testing-application-assertions
517+
/security/named_encoders /security/named_hashers

security/named_encoders.rst renamed to security/named_hashers.rst

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
.. index::
22
single: Security; Named Encoders
33

4-
How to Use A Different Password Encoder Algorithm Per User
5-
==========================================================
4+
How to Use A Different Password Hasher Algorithm Per User
5+
=========================================================
66

7-
Usually, the same password encoder is used for all users by configuring it
7+
Usually, the same password hasher is used for all users by configuring it
88
to apply to all instances of a specific class:
99

1010
.. configuration-block::
@@ -14,7 +14,7 @@ to apply to all instances of a specific class:
1414
# config/packages/security.yaml
1515
security:
1616
# ...
17-
encoders:
17+
password_hashers:
1818
App\Entity\User:
1919
algorithm: auto
2020
cost: 12
@@ -33,7 +33,7 @@ to apply to all instances of a specific class:
3333
>
3434
<config>
3535
<!-- ... -->
36-
<encoder class="App\Entity\User"
36+
<security:password-hasher class="App\Entity\User"
3737
algorithm="auto"
3838
cost="12"
3939
/>
@@ -47,21 +47,21 @@ to apply to all instances of a specific class:
4747
4848
$container->loadFromExtension('security', [
4949
// ...
50-
'encoders' => [
50+
'password_hashers' => [
5151
User::class => [
5252
'algorithm' => 'auto',
5353
'cost' => 12,
5454
],
5555
],
5656
]);
5757
58-
Another option is to use a "named" encoder and then select which encoder
58+
Another option is to use a "named" hasher and then select which hasher
5959
you want to use dynamically.
6060

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

6666
.. configuration-block::
6767

@@ -70,7 +70,7 @@ be done with named encoders:
7070
# config/packages/security.yaml
7171
security:
7272
# ...
73-
encoders:
73+
password_hashers:
7474
harsh:
7575
algorithm: auto
7676
cost: 15
@@ -90,7 +90,7 @@ be done with named encoders:
9090
9191
<config>
9292
<!-- ... -->
93-
<encoder class="harsh"
93+
<security:password-hasher class="harsh"
9494
algorithm="auto"
9595
cost="15"/>
9696
</config>
@@ -101,7 +101,7 @@ be done with named encoders:
101101
// config/packages/security.php
102102
$container->loadFromExtension('security', [
103103
// ...
104-
'encoders' => [
104+
'password_hashers' => [
105105
'harsh' => [
106106
'algorithm' => 'auto',
107107
'cost' => '15',
@@ -115,33 +115,33 @@ be done with named encoders:
115115
then the recommended hashing algorithm to use is
116116
:ref:`Sodium <reference-security-sodium>`.
117117

118-
This creates an encoder named ``harsh``. In order for a ``User`` instance
118+
This creates a hasher named ``harsh``. In order for a ``User`` instance
119119
to use it, the class must implement
120-
:class:`Symfony\\Component\\Security\\Core\\Encoder\\EncoderAwareInterface`.
121-
The interface requires one method - ``getEncoderName()`` - which should return
122-
the name of the encoder to use::
120+
:class:`Symfony\\Component\\PasswordHasher\\Hasher\\PasswordHasherAwareInterface`.
121+
The interface requires one method - ``getPasswordHasherName()`` - which should return
122+
the name of the hasher to use::
123123

124124
// src/Entity/User.php
125125
namespace App\Entity;
126126

127-
use Symfony\Component\Security\Core\Encoder\EncoderAwareInterface;
127+
use Symfony\Component\PasswordHasher\Hasher\PasswordHasherAwareInterface;
128128
use Symfony\Component\Security\Core\User\UserInterface;
129129

130-
class User implements UserInterface, EncoderAwareInterface
130+
class User implements UserInterface, PasswordHasherAwareInterface
131131
{
132-
public function getEncoderName(): ?string
132+
public function getPasswordHasherName(): ?string
133133
{
134134
if ($this->isAdmin()) {
135135
return 'harsh';
136136
}
137137

138-
return null; // use the default encoder
138+
return null; // use the default hasher
139139
}
140140
}
141141

142-
If you created your own password encoder implementing the
143-
:class:`Symfony\\Component\\Security\\Core\\Encoder\\PasswordEncoderInterface`,
144-
you must register a service for it in order to use it as a named encoder:
142+
If you created your own password hasher implementing the
143+
:class:`SSymfony\\Component\\PasswordHasher\\Hasher\\UserPasswordHasherInterface`,
144+
you must register a service for it in order to use it as a named hasher:
145145

146146
.. configuration-block::
147147

@@ -150,9 +150,9 @@ you must register a service for it in order to use it as a named encoder:
150150
# config/packages/security.yaml
151151
security:
152152
# ...
153-
encoders:
154-
app_encoder:
155-
id: 'App\Security\Encoder\MyCustomPasswordEncoder'
153+
password_hashers:
154+
app_hasher:
155+
id: 'App\Security\Hasher\MyCustomPasswordHasher'
156156
157157
.. code-block:: xml
158158
@@ -169,27 +169,27 @@ you must register a service for it in order to use it as a named encoder:
169169
170170
<config>
171171
<!-- ... -->
172-
<encoder class="app_encoder"
173-
id="App\Security\Encoder\MyCustomPasswordEncoder"/>
172+
<security:password_hasher class="app_hasher"
173+
id="App\Security\Hasher\MyCustomPasswordHasher"/>
174174
</config>
175175
</srv:container>
176176
177177
.. code-block:: php
178178
179179
// config/packages/security.php
180180
// ...
181-
use App\Security\Encoder\MyCustomPasswordEncoder;
181+
use App\Security\Hasher\MyCustomPasswordHasher;
182182
183183
$container->loadFromExtension('security', [
184184
// ...
185-
'encoders' => [
186-
'app_encoder' => [
187-
'id' => MyCustomPasswordEncoder::class,
185+
'password_hashers' => [
186+
'app_hasher' => [
187+
'id' => MyCustomPasswordHasher::class,
188188
],
189189
],
190190
]);
191191
192-
This creates an encoder named ``app_encoder`` from a service with the ID
193-
``App\Security\Encoder\MyCustomPasswordEncoder``.
192+
This creates a hasher named ``app_hasher`` from a service with the ID
193+
``App\Security\Hasher\MyCustomPasswordHasher``.
194194

195195
.. _`libsodium`: https://pecl.php.net/package/libsodium

0 commit comments

Comments
 (0)