@@ -1363,6 +1363,15 @@ any extra encoding. You can now calculate the hashed password either programmati
1363
1363
Supported algorithms for this method depend on your PHP version.
1364
1364
A full list is available calling the PHP function :phpfunction: `hash_algos `.
1365
1365
1366
+ .. caution ::
1367
+
1368
+ The above example is not meaned for practical usage, it uses a weak hash
1369
+ algorithm and it is only done to be able to generate the password easily. Using
1370
+ :ref: `BCrypt <reference-security-bcrypt >` is a better option.
1371
+
1372
+ .. versionadded :: 2.2
1373
+ The BCrypt encoder was introduced in Symfony 2.2.
1374
+
1366
1375
If you're creating your users dynamically (and storing them in a database),
1367
1376
you can use even tougher hashing algorithms and then rely on an actual password
1368
1377
encoder object to help you encode passwords. For example, suppose your User
@@ -1378,15 +1387,15 @@ configure the encoder for that user:
1378
1387
# ...
1379
1388
1380
1389
encoders :
1381
- Acme\UserBundle\Entity\User : sha512
1390
+ Acme\UserBundle\Entity\User : bcrypt
1382
1391
1383
1392
.. code-block :: xml
1384
1393
1385
1394
<!-- app/config/security.xml -->
1386
1395
<config >
1387
1396
<!-- ... -->
1388
1397
1389
- <encoder class =" Acme\UserBundle\Entity\User" algorithm =" sha512 " />
1398
+ <encoder class =" Acme\UserBundle\Entity\User" algorithm =" bcrypt " />
1390
1399
</config >
1391
1400
1392
1401
.. code-block :: php
@@ -1395,20 +1404,17 @@ configure the encoder for that user:
1395
1404
$container->loadFromExtension('security', array(
1396
1405
// ...
1397
1406
'encoders' => array(
1398
- 'Acme\UserBundle\Entity\User' => 'sha512 ',
1407
+ 'Acme\UserBundle\Entity\User' => 'bcrypt ',
1399
1408
),
1400
1409
));
1401
1410
1402
- In this case, you're using the stronger ``sha512 `` algorithm. Also, since
1403
- you've simply specified the algorithm (``sha512 ``) as a string, the system
1404
- will default to hashing your password 5000 times in a row and then encoding
1405
- it as base64. In other words, the password has been greatly obfuscated so
1406
- that the hashed password can't be decoded (i.e. you can't determine the password
1407
- from the hashed password).
1411
+ In this case, you're using the strong ``bcrypt `` algorithm. This means that the
1412
+ password has been greatly obfuscated so that the hashed password can't be
1413
+ decoded (i.e. you can't determine the password from the hashed password).
1408
1414
1409
1415
.. versionadded :: 2.2
1410
1416
As of Symfony 2.2 you can also use the :ref: `PBKDF2 <reference-security-pbkdf2 >`
1411
- and :ref: ` BCrypt < reference-security-bcrypt >` password encoders .
1417
+ password encoder .
1412
1418
1413
1419
Determining the Hashed Password
1414
1420
...............................
0 commit comments