Skip to content

Commit 00e5013

Browse files
committed
Deprecate the SecureRandom class
1 parent d1ae400 commit 00e5013

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

src/Symfony/Component/Security/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ CHANGELOG
1212
`Symfony\Component\Security\Http\Authentication\SimpleFormAuthenticatorInterface` instead
1313
* deprecated `Symfony\Component\Security\Core\Util\ClassUtils`, use
1414
`Symfony\Component\Security\Acl\Util\ClassUtils` instead
15+
* deprecated `Symfony\Component\Security\Core\Util\SecureRandom` class in favour of the `random_bytes` function
1516

1617
2.7.0
1718
-----

src/Symfony/Component/Security/Core/Util/SecureRandom.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,17 @@
1111

1212
namespace Symfony\Component\Security\Core\Util;
1313

14+
@trigger_error('The '.__NAMESPACE__.'\SecureRandom class is deprecated since 2.8 and will be removed in 3.0. Use the random_bytes function instead.', E_USER_DEPRECATED);
15+
1416
use Psr\Log\LoggerInterface;
1517

1618
/**
1719
* A secure random number generator implementation.
1820
*
1921
* @author Fabien Potencier <fabien@symfony.com>
2022
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
23+
*
24+
* @deprecated since 2.8, to be removed in 3.0. Use the random_bytes function instead
2125
*/
2226
final class SecureRandom implements SecureRandomInterface
2327
{
@@ -43,9 +47,9 @@ public function __construct($seedFile = null, LoggerInterface $logger = null)
4347
$this->logger = $logger;
4448

4549
// determine whether to use OpenSSL
46-
if (!function_exists('openssl_random_pseudo_bytes')) {
50+
if (!function_exists('random_bytes') || !function_exists('openssl_random_pseudo_bytes')) {
4751
if (null !== $this->logger) {
48-
$this->logger->notice('It is recommended that you enable the "openssl" extension for random number generation.');
52+
$this->logger->notice('It is recommended that you install the "paragonie/random_compat" library or enable the "openssl" extension for random number generation.');
4953
}
5054
$this->useOpenSsl = false;
5155
} else {
@@ -58,6 +62,10 @@ public function __construct($seedFile = null, LoggerInterface $logger = null)
5862
*/
5963
public function nextBytes($nbBytes)
6064
{
65+
if (function_exists('random_bytes')) {
66+
return random_bytes($nbBytes);
67+
}
68+
6169
// try OpenSSL
6270
if ($this->useOpenSsl) {
6371
$bytes = openssl_random_pseudo_bytes($nbBytes, $strong);

src/Symfony/Component/Security/Core/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
"symfony/http-foundation": "",
3434
"symfony/validator": "For using the user password constraint",
3535
"symfony/expression-language": "For using the expression voter",
36-
"ircmaxell/password-compat": "For using the BCrypt password encoder in PHP <5.5"
36+
"ircmaxell/password-compat": "For using the BCrypt password encoder in PHP <5.5",
37+
"paragonie/random_compat": "For secure number generation"
3738
},
3839
"autoload": {
3940
"psr-4": { "Symfony\\Component\\Security\\Core\\": "" }

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy