Skip to content

Commit aab3785

Browse files
committed
Document PasswordAuthenticatedInterface
1 parent 111ae11 commit aab3785

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

security/password_migration.rst

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,43 @@ Upgrade the Password
119119

120120
Upon successful login, the Security system checks whether a better algorithm
121121
is available to hash the user's password. If it is, it'll hash the correct
122-
password using the new hash. You can enable this behavior by implementing how
123-
this newly hashed password should be stored:
122+
password using the new hash. If you use a Guard authenticator, you first need to
123+
`provide the original password to the Security system <Provide the Password when using Guards>`_.
124+
125+
You can enable the upgrade behavior by implementing how this newly hashed
126+
password should be stored:
124127

125128
* `When using Doctrine's entity user provider <Upgrade the Password when using Doctrine>`_
126129
* `When using a custom user provider <Upgrade the Password when using a custom User Provider>`_
127130

128131
After this, you're done and passwords are always hashed as secure as possible!
129132

133+
Provide the Password when using Guards
134+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
135+
136+
When you're using a custom :doc:`guard authenticator </security/guard_authentication>`,
137+
you need to implement :class:`Symfony\\Component\\Security\\Guard\\PasswordAuthenticatedInterface`.
138+
This interfaces defines a ``getPassword()`` method that returns the password
139+
for this login request. This password is used in the migration process.
140+
141+
.. code-block:: php
142+
143+
// src/Security/TokenAuthenticator.php
144+
namespace App\Security;
145+
146+
use Symfony\Component\Security\Guard\PasswordAuthenticatedInterface;
147+
// ...
148+
149+
class CustomAuthenticator extends AbstractGuardAuthenticator implements PasswordAuthenticatedInterface
150+
{
151+
// ...
152+
153+
public function getPassword($credentials): ?string
154+
{
155+
return $credentials['password'];
156+
}
157+
}
158+
130159
Upgrade the Password when using Doctrine
131160
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
132161

0 commit comments

Comments
 (0)