Skip to content

Commit

Permalink
[#6104] Minor formatting fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
wouterj committed Feb 6, 2016
1 parent 932530f commit d6958d6
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions components/security/secure_tools.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Securely Generating Random Values
=================================
Securely Comparing Strings and Generating Random Values
=======================================================

The Symfony Security component comes with a collection of nice utilities
related to security. These utilities are used by Symfony, but you should
Expand All @@ -25,8 +25,7 @@ Generating a Secure Random String
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Whenever you need to generate a secure random string, you are highly
encouraged to use the
:phpfunction:`random_bytes` function::
encouraged to use the :phpfunction:`random_bytes` function::

$random = random_bytes(10);

Expand All @@ -35,26 +34,26 @@ the number bytes passed as an argument (10 in the above example).

.. tip::

The ``random_bytes()`` function returns a binary string which may contain the
``\0`` character. This can cause trouble in several common scenarios, such
as storing this value in a database or including it as part of the URL. The
solution is to encode or hash the value returned by ``random_bytes()`` (to do that, you
can use a simple ``base64_encode()`` PHP function).
The ``random_bytes()`` function returns a binary string which may contain
the ``\0`` character. This can cause trouble in several common scenarios,
such as storing this value in a database or including it as part of the
URL. The solution is to encode or hash the value returned by
``random_bytes()`` (to do that, you can use a simple ``base64_encode()``
PHP function).

Generating a Secure Random Number
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

If you need to generate a cryptographically secure random integer, you should
use the
:phpfunction:`random_int` function::
use the :phpfunction:`random_int` function::

$random = random_int(1, 10);

.. note::

PHP 7 and up provide the ``random_bytes()`` and ``random_int()`` functions natively,
for older versions of PHP a polyfill is provided by the `Symfony Polyfill Component`_
and the `paragonie/random_compat package`_.
PHP 7 and up provide the ``random_bytes()`` and ``random_int()`` functions
natively, for older versions of PHP a polyfill is provided by the
`Symfony Polyfill Component`_ and the `paragonie/random_compat package`_.

.. _`Timing attack`: https://en.wikipedia.org/wiki/Timing_attack
.. _`Symfony Polyfill Component`: https://github.com/symfony/polyfill
Expand Down

0 comments on commit d6958d6

Please sign in to comment.