@@ -115,14 +115,41 @@ Upgrade the Password
115
115
116
116
Upon successful login, the Security system checks whether a better algorithm
117
117
is available to hash the user's password. If it is, it'll hash the correct
118
- password using the new hash. You can enable this behavior by implementing how
119
- this newly hashed password should be stored:
118
+ password using the new hash. If you use a Guard authenticator, you first need to
119
+ `provide the original password to the Security system <Provide the Password when using Guards >`_.
120
+
121
+ You can enable the upgrade behavior by implementing how this newly hashed
122
+ password should be stored:
120
123
121
124
* `When using Doctrine's entity user provider <Upgrade the Password when using Doctrine >`_
122
125
* `When using a custom user provider <Upgrade the Password when using a custom User Provider >`_
123
126
124
127
After this, you're done and passwords are always hashed as secure as possible!
125
128
129
+ Provide the Password when using Guard
130
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
131
+
132
+ When you're using a custom :doc: `guard authenticator </security/guard_authentication >`,
133
+ you need to implement :class: `Symfony\\ Component\\ Security\\ Guard\\ PasswordAuthenticatedInterface `.
134
+ This interface defines a ``getPassword() `` method that returns the password
135
+ for this login request. This password is used in the migration process::
136
+
137
+ // src/Security/CustomAuthenticator.php
138
+ namespace App\Security;
139
+
140
+ use Symfony\Component\Security\Guard\PasswordAuthenticatedInterface;
141
+ // ...
142
+
143
+ class CustomAuthenticator extends AbstractGuardAuthenticator implements PasswordAuthenticatedInterface
144
+ {
145
+ // ...
146
+
147
+ public function getPassword($credentials): ?string
148
+ {
149
+ return $credentials['password'];
150
+ }
151
+ }
152
+
126
153
Upgrade the Password when using Doctrine
127
154
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
128
155
@@ -184,7 +211,7 @@ Trigger Password Migration From a Custom Encoder
184
211
If you're using a custom password encoder, you can trigger the password
185
212
migration by returning ``true `` in the ``needsRehash() `` method::
186
213
187
- // src/Security/UserProvider .php
214
+ // src/Security/CustomPasswordEncoder .php
188
215
namespace App\Security;
189
216
190
217
// ...
0 commit comments