-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Changed sha1 into bcrypt #3356
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changed sha1 into bcrypt #3356
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1358,6 +1358,15 @@ the password is simply run through the ``sha1`` algorithm one time and without | |
any extra encoding. You can now calculate the hashed password either programmatically | ||
(e.g. ``hash('sha1', 'ryanpass')``) or via some online tool like `functions-online.com`_ | ||
|
||
.. caution:: | ||
|
||
The above example is not meaned for practical usage, it uses a weak hash | ||
algorithm and it is only done to be able to generate the password easily. Using | ||
:ref:`BCrypt <reference-security-bcrypt>` is a better option. | ||
|
||
.. versionadded:: 2.2 | ||
The BCrypt encoder was introduced in Symfony 2.2. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we really need this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it was in the versionadded below before this pr There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see. |
||
|
||
If you're creating your users dynamically (and storing them in a database), | ||
you can use even tougher hashing algorithms and then rely on an actual password | ||
encoder object to help you encode passwords. For example, suppose your User | ||
|
@@ -1373,15 +1382,15 @@ configure the encoder for that user: | |
# ... | ||
|
||
encoders: | ||
Acme\UserBundle\Entity\User: sha512 | ||
Acme\UserBundle\Entity\User: bcrypt | ||
|
||
.. code-block:: xml | ||
|
||
<!-- app/config/security.xml --> | ||
<config> | ||
<!-- ... --> | ||
|
||
<encoder class="Acme\UserBundle\Entity\User" algorithm="sha512" /> | ||
<encoder class="Acme\UserBundle\Entity\User" algorithm="bcrypt" /> | ||
</config> | ||
|
||
.. code-block:: php | ||
|
@@ -1390,20 +1399,17 @@ configure the encoder for that user: | |
$container->loadFromExtension('security', array( | ||
// ... | ||
'encoders' => array( | ||
'Acme\UserBundle\Entity\User' => 'sha512', | ||
'Acme\UserBundle\Entity\User' => 'bcrypt', | ||
), | ||
)); | ||
|
||
In this case, you're using the stronger ``sha512`` algorithm. Also, since | ||
you've simply specified the algorithm (``sha512``) as a string, the system | ||
will default to hashing your password 5000 times in a row and then encoding | ||
it as base64. In other words, the password has been greatly obfuscated so | ||
that the hashed password can't be decoded (i.e. you can't determine the password | ||
from the hashed password). | ||
In this case, you're using the strong ``bcrypt`` algorithm. This means that the | ||
password has been greatly obfuscated so that the hashed password can't be | ||
decoded (i.e. you can't determine the password from the hashed password). | ||
|
||
.. versionadded:: 2.2 | ||
As of Symfony 2.2 you can also use the :ref:`PBKDF2 <reference-security-pbkdf2>` | ||
and :ref:`BCrypt <reference-security-bcrypt>` password encoders. | ||
password encoder. | ||
|
||
Determining the Hashed Password | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this section still true? |
||
............................... | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left the above example with sha1, because when using bcrypt it would be hard to get the hashed password.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is not meant