@@ -1198,6 +1198,74 @@ from the hashed password).
1198
1198
.. versionadded :: 2.2
1199
1199
As of Symfony 2.2 you can also use the PBKDF2 password encoder.
1200
1200
1201
+ Using the BCrypt Password Encoder
1202
+ .................................
1203
+
1204
+ .. versionadded :: 2.2
1205
+ The BCrypt password encoder was added in Symfony 2.2.
1206
+
1207
+ .. configuration-block ::
1208
+
1209
+ .. code-block :: yaml
1210
+
1211
+ # app/config/security.yml
1212
+ security :
1213
+ # ...
1214
+ encoders :
1215
+ Symfony\Component\Security\Core\User\User :
1216
+ algorithm : bcrypt
1217
+ cost : 15
1218
+
1219
+ .. code-block :: xml
1220
+
1221
+ <!-- app/config/security.xml -->
1222
+ <config >
1223
+ <!-- ... -->
1224
+ <encoder
1225
+ class =" Symfony\Component\Security\Core\User\User"
1226
+ algorithm =" bcrypt"
1227
+ cost =" 15"
1228
+ />
1229
+ </config >
1230
+
1231
+ .. code-block :: php
1232
+
1233
+ // app/config/security.php
1234
+ $container->loadFromExtension('security', array(
1235
+ // ...
1236
+ 'encoders' => array(
1237
+ 'Symfony\Component\Security\Core\User\User' => array(
1238
+ 'algorithm' => 'bcrypt',
1239
+ 'cost' => 15,
1240
+ ),
1241
+ ),
1242
+ ));
1243
+
1244
+ ``cost `` can be in the range of ``4-31 `` and determines how long a password
1245
+ will be encoded. Each increment of ``cost `` *doubles * the time it takes to
1246
+ encode a password.
1247
+
1248
+ If you don't provide the ``cost `` option, the default cost of ``13 `` is used.
1249
+
1250
+ .. note ::
1251
+
1252
+ You can change the cost at any time — even if you already have some
1253
+ passwords encoded using a different cost. New passwords will be encoded
1254
+ using the new cost, while the already encoded ones will be validated
1255
+ using a cost that was used back when they were encoded.
1256
+
1257
+ A salt for each new password is generated automatically and need not be
1258
+ persisted. Since an encoded password contains the salt used to encode it,
1259
+ persisting the encoded password alone is enough.
1260
+
1261
+ .. note ::
1262
+
1263
+ All the encoded passwords are ``60 `` characters long, so make sure to
1264
+ allocate enough space for them to be persisted.
1265
+
1266
+ Determining the Hashed Password
1267
+ ...............................
1268
+
1201
1269
If you have some sort of registration form for users, you'll need to be able
1202
1270
to determine the hashed password so that you can set it on your user. No
1203
1271
matter what algorithm you configure for your user object, the hashed password
0 commit comments