Skip to content

Commit 9045d4b

Browse files
morillexabbuh
authored andcommitted
Referencing custom encoders as named encoders
1 parent ca0c86c commit 9045d4b

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

security/named_encoders.rst

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,50 @@ the name of the encoder to use::
124124
return null; // use the default encoder
125125
}
126126
}
127+
128+
If you implemented your own password encoder as explained in
129+
:doc:`authentication </security/authentication>`,
130+
you can also use it as a named encoder, note that it must be registered as a service.
131+
132+
.. configuration-block::
133+
134+
.. code-block:: yaml
135+
136+
# app/config/security.yml
137+
security:
138+
# ...
139+
encoders:
140+
app_encoder:
141+
id: 'app.password_encoder_service'
142+
143+
.. code-block:: xml
144+
145+
<!-- app/config/security.xml -->
146+
<?xml version="1.0" encoding="UTF-8" ?>
147+
<srv:container xmlns="http://symfony.com/schema/dic/security"
148+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
149+
xmlns:srv="http://symfony.com/schema/dic/services"
150+
xsi:schemaLocation="http://symfony.com/schema/dic/services
151+
http://symfony.com/schema/dic/services/services-1.0.xsd"
152+
>
153+
154+
<config>
155+
<!-- ... -->
156+
<encoder class="app_encoder"
157+
id="app.password_encoder_service" />
158+
</config>
159+
</srv:container>
160+
161+
.. code-block:: php
162+
163+
// app/config/security.php
164+
$container->loadFromExtension('security', array(
165+
// ...
166+
'encoders' => array(
167+
'app_encoder' => array(
168+
'id' => 'app.password_encoder_service'
169+
),
170+
),
171+
));
172+
173+
This creates an encoder named ``app_encoder`` from a service named ``app.password_encoder_service``.

0 commit comments

Comments
 (0)