Skip to content

Referencing custom encoders as named encoders #8315

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions security/named_encoders.rst
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,51 @@ the name of the encoder to use::
return null; // use the default encoder
}
}

If you created your own password encoder implementing the
:class:`Symfony\\Component\\Security\\Core\\Encoder\\PasswordEncoderInterface`,
you must register a service for it in order to use it as a named encoder:

.. configuration-block::

.. code-block:: yaml

# app/config/security.yml
security:
# ...
encoders:
app_encoder:
id: 'app.password_encoder_service'

.. code-block:: xml

<!-- app/config/security.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<srv:container xmlns="http://symfony.com/schema/dic/security"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:srv="http://symfony.com/schema/dic/services"
xsi:schemaLocation="http://symfony.com/schema/dic/services
http://symfony.com/schema/dic/services/services-1.0.xsd"
>

<config>
<!-- ... -->
<encoder class="app_encoder"
id="app.password_encoder_service" />
</config>
</srv:container>

.. code-block:: php

// app/config/security.php
$container->loadFromExtension('security', array(
// ...
'encoders' => array(
'app_encoder' => array(
'id' => 'app.password_encoder_service'
),
),
));

This creates an encoder named ``app_encoder`` from a service named
``app.password_encoder_service``.