@@ -35,8 +35,8 @@ method.
35
35
36
36
This is how your ``WebserviceUser `` class looks in action::
37
37
38
- // src/Acme/WebserviceUserBundle /Security/User/WebserviceUser.php
39
- namespace Acme\WebserviceUserBundle \Security\User;
38
+ // src/AppBundle /Security/User/WebserviceUser.php
39
+ namespace AppBundle \Security\User;
40
40
41
41
use Symfony\Component\Security\Core\User\UserInterface;
42
42
use Symfony\Component\Security\Core\User\EquatableInterface;
@@ -120,8 +120,8 @@ more details, see :class:`Symfony\\Component\\Security\\Core\\User\\UserProvider
120
120
121
121
Here's an example of how this might look::
122
122
123
- // src/Acme/WebserviceUserBundle /Security/User/WebserviceUserProvider.php
124
- namespace Acme\WebserviceUserBundle \Security\User;
123
+ // src/AppBundle /Security/User/WebserviceUserProvider.php
124
+ namespace AppBundle \Security\User;
125
125
126
126
use Symfony\Component\Security\Core\User\UserProviderInterface;
127
127
use Symfony\Component\Security\Core\User\UserInterface;
@@ -162,7 +162,7 @@ Here's an example of how this might look::
162
162
163
163
public function supportsClass($class)
164
164
{
165
- return $class === 'Acme\WebserviceUserBundle \Security\User\WebserviceUser';
165
+ return $class === 'AppBundle \Security\User\WebserviceUser';
166
166
}
167
167
}
168
168
@@ -177,8 +177,8 @@ Now you make the user provider available as a service:
177
177
178
178
# app/config/services.yml
179
179
services :
180
- webservice_user_provider :
181
- class : Acme\WebserviceUserBundle \Security\User\WebserviceUserProvider
180
+ app. webservice_user_provider :
181
+ class : AppBundle \Security\User\WebserviceUserProvider
182
182
183
183
.. code-block :: xml
184
184
@@ -190,8 +190,8 @@ Now you make the user provider available as a service:
190
190
http://symfony.com/schema/dic/services/services-1.0.xsd" >
191
191
192
192
<services >
193
- <service id =" webservice_user_provider"
194
- class =" Acme\WebserviceUserBundle \Security\User\WebserviceUserProvider"
193
+ <service id =" app. webservice_user_provider"
194
+ class =" AppBundle \Security\User\WebserviceUserProvider"
195
195
/>
196
196
</services >
197
197
</container >
@@ -202,8 +202,8 @@ Now you make the user provider available as a service:
202
202
use Symfony\Component\DependencyInjection\Definition;
203
203
204
204
$container->setDefinition(
205
- 'webservice_user_provider',
206
- new Definition('Acme\WebserviceUserBundle \Security\User\WebserviceUserProvider')
205
+ 'app. webservice_user_provider',
206
+ new Definition('AppBundle \Security\User\WebserviceUserProvider')
207
207
);
208
208
209
209
.. tip ::
@@ -222,7 +222,7 @@ Modify ``security.yml``
222
222
223
223
Everything comes together in your security configuration. Add the user provider
224
224
to the list of providers in the "security" section. Choose a name for the user provider
225
- (e.g. "webservice") and mention the id of the service you just defined.
225
+ (e.g. "webservice") and mention the `` id `` of the service you just defined.
226
226
227
227
.. configuration-block ::
228
228
@@ -234,7 +234,7 @@ to the list of providers in the "security" section. Choose a name for the user p
234
234
235
235
providers :
236
236
webservice :
237
- id : webservice_user_provider
237
+ id : app. webservice_user_provider
238
238
239
239
.. code-block :: xml
240
240
@@ -249,7 +249,7 @@ to the list of providers in the "security" section. Choose a name for the user p
249
249
<config >
250
250
<!-- ... -->
251
251
252
- <provider name =" webservice" id =" webservice_user_provider" />
252
+ <provider name =" webservice" id =" app. webservice_user_provider" />
253
253
</config >
254
254
</srv : container >
255
255
@@ -261,7 +261,7 @@ to the list of providers in the "security" section. Choose a name for the user p
261
261
262
262
'providers' => array(
263
263
'webservice' => array(
264
- 'id' => 'webservice_user_provider',
264
+ 'id' => 'app. webservice_user_provider',
265
265
),
266
266
),
267
267
));
@@ -279,7 +279,7 @@ users, e.g. by filling in a login form. You can do this by adding a line to the
279
279
# ...
280
280
281
281
encoders :
282
- Acme\WebserviceUserBundle\ Security\User\WebserviceUser : sha512
282
+ AppBundle\ Security\User\WebserviceUser : bcrypt
283
283
284
284
.. code-block :: xml
285
285
@@ -294,9 +294,8 @@ users, e.g. by filling in a login form. You can do this by adding a line to the
294
294
<config >
295
295
<!-- ... -->
296
296
297
- <encoder class =" Acme\WebserviceUserBundle\Security\User\WebserviceUser"
298
- algorithm =" sha512"
299
- />
297
+ <encoder class =" AppBundle\Security\User\WebserviceUser"
298
+ algorithm =" bcrypt" />
300
299
</config >
301
300
</srv : container >
302
301
@@ -307,16 +306,15 @@ users, e.g. by filling in a login form. You can do this by adding a line to the
307
306
// ...
308
307
309
308
'encoders' => array(
310
- 'Acme\WebserviceUserBundle\ Security\User\WebserviceUser' => 'sha512 ',
309
+ 'AppBundle\ Security\User\WebserviceUser' => 'bcrypt ',
311
310
),
311
+ // ...
312
312
));
313
313
314
314
The value here should correspond with however the passwords were originally
315
315
encoded when creating your users (however those users were created). When
316
- a user submits their password, the salt value is appended to the password and
317
- then encoded using this algorithm before being compared to the hashed password
318
- returned by your ``getPassword() `` method. Additionally, depending on your
319
- options, the password may be encoded multiple times and encoded to base64.
316
+ a user submits their password, it's encoded using this algorithm and the result
317
+ is compared to the hashed password returned by your ``getPassword() `` method.
320
318
321
319
.. sidebar :: Specifics on how Passwords are Encoded
322
320
@@ -331,12 +329,12 @@ options, the password may be encoded multiple times and encoded to base64.
331
329
If your external users have their passwords salted via a different method,
332
330
then you'll need to do a bit more work so that Symfony properly encodes
333
331
the password. That is beyond the scope of this entry, but would include
334
- sub-classing ``MessageDigestPasswordEncoder `` and overriding the `` mergePasswordAndSalt ``
335
- method.
332
+ sub-classing ``MessageDigestPasswordEncoder `` and overriding the
333
+ `` mergePasswordAndSalt `` method.
336
334
337
- Additionally, the hash, by default, is encoded multiple times and encoded
338
- to base64. For specific details, see ` MessageDigestPasswordEncoder `_.
339
- To prevent this, configure it in your configuration file :
335
+ Additionally, you can configure the details of the algorithm used to hash
336
+ passwords. In this example, the application sets explicitly the cost of
337
+ the bcrypt hashing :
340
338
341
339
.. configuration-block ::
342
340
@@ -347,10 +345,9 @@ options, the password may be encoded multiple times and encoded to base64.
347
345
# ...
348
346
349
347
encoders :
350
- Acme\WebserviceUserBundle\Security\User\WebserviceUser :
351
- algorithm : sha512
352
- encode_as_base64 : false
353
- iterations : 1
348
+ AppBundle\Security\User\WebserviceUser :
349
+ algorithm : bcrypt
350
+ cost : 12
354
351
355
352
.. code-block :: xml
356
353
@@ -365,11 +362,9 @@ options, the password may be encoded multiple times and encoded to base64.
365
362
<config >
366
363
<!-- ... -->
367
364
368
- <encoder class =" Acme\WebserviceUserBundle\Security\User\WebserviceUser"
369
- algorithm =" sha512"
370
- encode-as-base64 =" false"
371
- iterations =" 1"
372
- />
365
+ <encoder class =" AppBundle\Security\User\WebserviceUser"
366
+ algorithm =" bcrypt"
367
+ cost =" 12" />
373
368
</config >
374
369
</srv : container >
375
370
@@ -380,12 +375,12 @@ options, the password may be encoded multiple times and encoded to base64.
380
375
// ...
381
376
382
377
'encoders' => array(
383
- 'Acme\WebserviceUserBundle\Security\User\WebserviceUser' => array(
384
- 'algorithm' => 'sha512',
385
- 'encode_as_base64' => false,
386
- 'iterations' => 1,
387
- ),
378
+ 'AppBundle\Security\User\WebserviceUser' => array(
379
+ 'algorithm' => 'bcrypt',
380
+ 'cost' => 12,
381
+ )
388
382
),
383
+ // ...
389
384
));
390
385
391
386
.. _MessageDigestPasswordEncoder : https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Security/Core/Encoder/MessageDigestPasswordEncoder.php
0 commit comments