Skip to content

Commit 8018c29

Browse files
committed
Deprecate the SecureRandom class
1 parent d1ae400 commit 8018c29

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
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: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
*
1919
* @author Fabien Potencier <fabien@symfony.com>
2020
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
21+
*
22+
* @deprecated This class is deprecated since 2.8 and will be removed in 3.0. Use the random_bytes function instead
2123
*/
2224
final class SecureRandom implements SecureRandomInterface
2325
{
@@ -44,7 +46,7 @@ public function __construct($seedFile = null, LoggerInterface $logger = null)
4446

4547
// determine whether to use OpenSSL
4648
if (!function_exists('openssl_random_pseudo_bytes')) {
47-
if (null !== $this->logger) {
49+
if (null !== $this->logger && !function_exists('random_bytes')) {
4850
$this->logger->notice('It is recommended that you enable the "openssl" extension for random number generation.');
4951
}
5052
$this->useOpenSsl = false;
@@ -58,6 +60,12 @@ public function __construct($seedFile = null, LoggerInterface $logger = null)
5860
*/
5961
public function nextBytes($nbBytes)
6062
{
63+
@trigger_error('The '.__CLASS__.' class is deprecated since 2.8 and will be removed in 3.0. Use the random_bytes function instead', E_USER_DEPRECATED);
64+
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