@@ -124,75 +124,65 @@ Further in this article, you can find a
124
124
125
125
.. code-block :: yaml
126
126
127
- # config/packages/test/security.yaml
128
- security :
129
- # ...
130
-
131
- password_hashers :
132
- # Use your user class name here
133
- App\Entity\User :
134
- algorithm : plaintext # disable hashing (only do this in tests!)
135
-
136
- # or use the lowest possible values
137
- App\Entity\User :
138
- algorithm : auto # This should be the same value as in config/packages/security.yaml
139
- cost : 4 # Lowest possible value for bcrypt
140
- time_cost : 3 # Lowest possible value for argon
141
- memory_cost : 10 # Lowest possible value for argon
127
+ # config/packages/security.yaml
128
+ when@test :
129
+ security :
130
+ # ...
131
+
132
+ password_hashers :
133
+ # Use your user class name here
134
+ App\Entity\User :
135
+ algorithm : auto
136
+ cost : 4 # Lowest possible value for bcrypt
137
+ time_cost : 3 # Lowest possible value for argon
138
+ memory_cost : 10 # Lowest possible value for argon
142
139
143
140
.. code-block :: xml
144
141
145
- <!-- config/packages/test/ security.xml -->
142
+ <!-- config/packages/security.xml -->
146
143
<?xml version =" 1.0" encoding =" UTF-8" ?>
147
144
<srv : container xmlns =" http://symfony.com/schema/dic/security"
148
145
xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
149
146
xmlns : srv =" http://symfony.com/schema/dic/services"
150
147
xsi : schemaLocation =" http://symfony.com/schema/dic/services
151
148
https://symfony.com/schema/dic/services/services-1.0.xsd" >
152
149
153
- <config >
154
- <!-- class: Use your user class name here -->
155
- <!-- algorithm: disable hashing (only do this in tests!) -->
156
- <security : password-hasher
157
- class =" App\Entity\User"
158
- algorithm =" plaintext"
159
- />
160
-
161
- <!-- or use the lowest possible values -->
162
- <!-- algorithm: This should be the same value as in config/packages/security.yaml -->
163
- <!-- cost: Lowest possible value for bcrypt -->
164
- <!-- time_cost: Lowest possible value for argon -->
165
- <!-- memory_cost: Lowest possible value for argon -->
166
- <security : password-hasher
167
- class =" App\Entity\User"
168
- algorithm =" auto"
169
- cost =" 4"
170
- time_cost =" 3"
171
- memory_cost =" 10"
172
- />
173
- </config >
150
+ <when env =" test" >
151
+ <config >
152
+ <!-- class: Use your user class name here -->
153
+ <!-- cost: Lowest possible value for bcrypt -->
154
+ <!-- time_cost: Lowest possible value for argon -->
155
+ <!-- memory_cost: Lowest possible value for argon -->
156
+ <security : password-hasher
157
+ class =" App\Entity\User"
158
+ algorithm =" auto"
159
+ cost =" 4"
160
+ time_cost =" 3"
161
+ memory_cost =" 10"
162
+ />
163
+ </config >
164
+ </when >
174
165
</srv : container >
175
166
176
167
.. code-block :: php
177
168
178
- // config/packages/test/ security.php
169
+ // config/packages/security.php
179
170
use App\Entity\User;
171
+ use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
180
172
use Symfony\Config\SecurityConfig;
181
173
182
- return static function (SecurityConfig $security): void {
174
+ return static function (SecurityConfig $security, ContainerConfigurator $container ): void {
183
175
// ...
184
176
185
- // Use your user class name here
186
- $security->passwordHasher(User::class)
187
- ->algorithm('plaintext'); // disable hashing (only do this in tests!)
188
-
189
- // or use the lowest possible values
190
- $security->passwordHasher(User::class)
191
- ->algorithm('auto') // This should be the same value as in config/packages/security.yaml
192
- ->cost(4) // Lowest possible value for bcrypt
193
- ->timeCost(2) // Lowest possible value for argon
194
- ->memoryCost(10) // Lowest possible value for argon
195
- ;
177
+ if ('test' === $container->env()) {
178
+ // Use your user class name here
179
+ $security->passwordHasher(User::class)
180
+ ->algorithm('auto') // This should be the same value as in config/packages/security.yaml
181
+ ->cost(4) // Lowest possible value for bcrypt
182
+ ->timeCost(2) // Lowest possible value for argon
183
+ ->memoryCost(10) // Lowest possible value for argon
184
+ ;
185
+ }
196
186
};
197
187
198
188
Hashing the Password
0 commit comments