@@ -215,39 +215,34 @@ hashing algorithm. Also, each algorithm defines different config options:
215
215
216
216
// config/packages/security.php
217
217
use App\Entity\User;
218
+ use Symfony\Config\SecurityConfig;
218
219
219
- $container->loadFromExtension(' security', [
220
+ return static function (SecurityConfig $ security) {
220
221
// ...
221
- 'password_hashers' => [
222
- // auto hasher with default options
223
- User::class => [
224
- 'algorithm' => 'auto',
225
- ],
226
-
227
- // auto hasher with custom options
228
- User::class => [
229
- 'algorithm' => 'auto',
230
- 'cost' => 15,
231
- ],
232
-
233
- // Sodium hasher with default options
234
- User::class => [
235
- 'algorithm' => 'sodium',
236
- ],
237
-
238
- // Sodium hasher with custom options
239
- User::class => [
240
- 'algorithm' => 'sodium',
241
- 'memory_cost' => 16384, // Amount in KiB. (16384 = 16 MiB)
242
- 'time_cost' => 2, // Number of iterations
243
- ],
244
-
245
- // MessageDigestPasswordHasher hasher using SHA512 hashing with default options
246
- User::class => [
247
- 'algorithm' => 'sha512',
248
- ],
249
- ],
250
- ]);
222
+
223
+ // auto hasher with default options
224
+ $security->passwordHasher(User::class)
225
+ ->algorithm('auto');
226
+
227
+ // auto hasher with custom options
228
+ $security->passwordHasher(User::class)
229
+ ->algorithm('auto')
230
+ ->cost(15);
231
+
232
+ // Sodium hasher with default options
233
+ $security->passwordHasher(User::class)
234
+ ->algorithm('sodium');
235
+
236
+ // Sodium hasher with custom options
237
+ $security->passwordHasher(User::class)
238
+ ->algorithm('sodium')
239
+ ->memoryCost(16384) // Amount in KiB. (16384 = 16 MiB)
240
+ ->timeCost(2); // Number of iterations
241
+
242
+ // MessageDigestPasswordHasher hasher using SHA512 hashing with default options
243
+ $security->passwordHasher(User::class)
244
+ ->algorithm('sha512');
245
+ };
251
246
252
247
.. versionadded :: 5.3
253
248
@@ -310,18 +305,19 @@ hashing algorithm. Also, each algorithm defines different config options:
310
305
311
306
// config/packages/test/security.php
312
307
use App\Entity\User;
308
+ use Symfony\Config\SecurityConfig;
309
+
310
+ return static function (SecurityConfig $security) {
311
+ // ...
313
312
314
- $container->loadFromExtension('security', [
315
- 'password_hashers' => [
316
- // Use your user class name here
317
- User::class => [
318
- 'algorithm' => 'auto', // This should be the same value as in config/packages/security.yaml
319
- 'cost' => 4, // Lowest possible value for bcrypt
320
- 'time_cost' => 3, // Lowest possible value for argon
321
- 'memory_cost' => 10, // Lowest possible value for argon
322
- ]
323
- ],
324
- ]);
313
+ // Use your user class name here
314
+ $security->passwordHasher(User::class)
315
+ ->algorithm('auto') // This should be the same value as in config/packages/security.yaml
316
+ ->cost(4) // Lowest possible value for bcrypt
317
+ ->timeCost(2) // Lowest possible value for argon
318
+ ->memoryCost(10) // Lowest possible value for argon
319
+ ;
320
+ };
325
321
326
322
.. _reference-security-sodium :
327
323
.. _using-the-argon2i-password-encoder :
@@ -432,20 +428,20 @@ application:
432
428
.. code-block :: php
433
429
434
430
// config/packages/security.php
431
+ use Symfony\Config\SecurityConfig;
432
+
433
+ return static function (SecurityConfig $security) {
434
+ // ...
435
435
436
- // ...
437
- $container->loadFromExtension('security', [
438
- 'firewalls' => [
439
- // 'main' is the name of the firewall (can be chosen freely)
440
- 'main' => [
441
- // 'pattern' is a regular expression matched against the incoming
442
- // request URL. If there's a match, authentication is triggered
443
- 'pattern' => '^/admin',
444
- // the rest of options depend on the authentication mechanism
445
- // ...
446
- ],
447
- ],
448
- ]);
436
+ // 'main' is the name of the firewall (can be chosen freely)
437
+ $security->firewall('main')
438
+ // 'pattern' is a regular expression matched against the incoming
439
+ // request URL. If there's a match, authentication is triggered
440
+ ->pattern('^/admin')
441
+ // the rest of options depend on the authentication mechanism
442
+ // ...
443
+ ;
444
+ };
449
445
450
446
.. seealso ::
451
447
@@ -807,18 +803,19 @@ multiple firewalls, the "context" could actually be shared:
807
803
.. code-block :: php
808
804
809
805
// config/packages/security.php
810
- $container->loadFromExtension('security', [
811
- 'firewalls' => [
812
- 'somename' => [
813
- // ...
814
- 'context' => 'my_context',
815
- ],
816
- 'othername' => [
817
- // ...
818
- 'context' => 'my_context',
819
- ],
820
- ],
821
- ]);
806
+ use Symfony\Config\SecurityConfig;
807
+
808
+ return static function (SecurityConfig $security) {
809
+ $security->firewall('somename')
810
+ // ...
811
+ ->context('my_context')
812
+ ;
813
+
814
+ $security->firewall('othername')
815
+ // ...
816
+ ->context('my_context')
817
+ ;
818
+ };
822
819
823
820
.. note ::
824
821
0 commit comments