Skip to content

Commit d7e0fb9

Browse files
committed
Merge branch '2.5' into 2.6
Conflicts: book/security.rst
2 parents abc88ee + 7cc4287 commit d7e0fb9

File tree

1 file changed

+6
-33
lines changed

1 file changed

+6
-33
lines changed

book/security.rst

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,8 +1203,7 @@ Thanks to the SensioFrameworkExtraBundle, you can also secure your controller us
12031203
// ...
12041204
}
12051205

1206-
For more information, see the
1207-
`FrameworkExtraBundle documentation <http://symfony.com/doc/master/bundles/SensioFrameworkExtraBundle/annotations/security.html>`_.
1206+
For more information, see the `FrameworkExtraBundle documentation`_.
12081207

12091208
Securing other Services
12101209
~~~~~~~~~~~~~~~~~~~~~~~
@@ -1567,57 +1566,30 @@ is available by calling the PHP function :phpfunction:`hash_algos`.
15671566
Determining the Hashed Password
15681567
...............................
15691568

1570-
.. versionadded:: 2.6
1571-
The ``security.password_encoder`` service was introduced in Symfony 2.6.
1572-
15731569
If you're storing users in the database and you have some sort of registration
15741570
form for users, you'll need to be able to determine the hashed password so
15751571
that you can set it on your user before inserting it. No matter what algorithm
15761572
you configure for your user object, the hashed password can always be determined
15771573
in the following way from a controller::
15781574

1575+
$factory = $this->get('security.encoder_factory');
15791576
$user = new Acme\UserBundle\Entity\User();
1580-
$plainPassword = 'ryanpass';
1581-
$encoded = $this->container->get('security.password_encoder')
1582-
->encodePassword($user, $plainPassword);
15831577

1584-
$user->setPassword($encoded);
1578+
$encoder = $factory->getEncoder($user);
1579+
$password = $encoder->encodePassword('ryanpass', $user->getSalt());
1580+
$user->setPassword($password);
15851581

15861582
In order for this to work, just make sure that you have the encoder for your
15871583
user class (e.g. ``Acme\UserBundle\Entity\User``) configured under the ``encoders``
15881584
key in ``app/config/security.yml``.
15891585

1590-
.. sidebar:: Get the User Encoder
1591-
1592-
In some cases, you need a specific encoder for a given user (e.g. ``Acme\UserBundle\Entity\User``).
1593-
You can use the ``EncoderFactory`` to get this encoder::
1594-
1595-
$factory = $this->get('security.encoder_factory');
1596-
$user = new Acme\UserBundle\Entity\User();
1597-
1598-
$encoder = $factory->getEncoder($user);
1599-
16001586
.. caution::
16011587

16021588
When you allow a user to submit a plaintext password (e.g. registration
16031589
form, change password form), you *must* have validation that guarantees
16041590
that the password is 4096 characters or less. Read more details in
16051591
:ref:`How to implement a simple Registration Form <cookbook-registration-password-max>`.
16061592

1607-
Validating a Plaintext Password
1608-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1609-
1610-
Sometimes you want to check if a plain password is valid for a given user::
1611-
1612-
// a user instance of some class which implements Symfony\Component\Security\Core\User\UserInterface
1613-
$user = ...;
1614-
1615-
// the password that should be checked
1616-
$plainPassword = ...;
1617-
1618-
$isValidPassword = $this->container->get('security.password_encoder')
1619-
->isPasswordValid($user, $plainPassword);
1620-
16211593
Retrieving the User Object
16221594
~~~~~~~~~~~~~~~~~~~~~~~~~~
16231595

@@ -2331,6 +2303,7 @@ Learn more from the Cookbook
23312303
* :doc:`/cookbook/security/remember_me`
23322304
* :doc:`How to Restrict Firewalls to a Specific Request </cookbook/security/firewall_restriction>`
23332305

2306+
.. _`FrameworkExtraBundle documentation`: http://symfony.com/doc/master/bundles/SensioFrameworkExtraBundle/annotations/security.html
23342307
.. _`FOSUserBundle`: https://github.com/FriendsOfSymfony/FOSUserBundle
23352308
.. _`implement the \Serializable interface`: http://php.net/manual/en/class.serializable.php
23362309
.. _`Timing attack`: http://en.wikipedia.org/wiki/Timing_attack

0 commit comments

Comments
 (0)