diff options
-rw-r--r-- | composer.json | 3 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Tools/Utils.php | 15 |
2 files changed, 6 insertions, 12 deletions
diff --git a/composer.json b/composer.json index 78b32307..d84e1f8b 100644 --- a/composer.json +++ b/composer.json | |||
@@ -62,7 +62,8 @@ | |||
62 | "wallabag/php-mobi": "~1.0.0", | 62 | "wallabag/php-mobi": "~1.0.0", |
63 | "kphoen/rulerz-bundle": "~0.10", | 63 | "kphoen/rulerz-bundle": "~0.10", |
64 | "guzzlehttp/guzzle": "^5.2.0", | 64 | "guzzlehttp/guzzle": "^5.2.0", |
65 | "doctrine/doctrine-migrations-bundle": "^1.0" | 65 | "doctrine/doctrine-migrations-bundle": "^1.0", |
66 | "paragonie/random_compat": "~1.0" | ||
66 | }, | 67 | }, |
67 | "require-dev": { | 68 | "require-dev": { |
68 | "doctrine/doctrine-fixtures-bundle": "~2.2", | 69 | "doctrine/doctrine-fixtures-bundle": "~2.2", |
diff --git a/src/Wallabag/CoreBundle/Tools/Utils.php b/src/Wallabag/CoreBundle/Tools/Utils.php index a16baca9..71cbc490 100644 --- a/src/Wallabag/CoreBundle/Tools/Utils.php +++ b/src/Wallabag/CoreBundle/Tools/Utils.php | |||
@@ -7,20 +7,13 @@ class Utils | |||
7 | /** | 7 | /** |
8 | * Generate a token used for RSS. | 8 | * Generate a token used for RSS. |
9 | * | 9 | * |
10 | * @param integer $length Length of the token | ||
11 | * | ||
10 | * @return string | 12 | * @return string |
11 | */ | 13 | */ |
12 | public static function generateToken() | 14 | public static function generateToken($length = 15) |
13 | { | 15 | { |
14 | if (ini_get('open_basedir') === '') { | 16 | $token = substr(base64_encode(random_bytes($length)), 0, $length); |
15 | if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { | ||
16 | // alternative to /dev/urandom for Windows | ||
17 | $token = substr(base64_encode(uniqid(mt_rand(), true)), 0, 20); | ||
18 | } else { | ||
19 | $token = substr(base64_encode(file_get_contents('/dev/urandom', false, null, 0, 20)), 0, 15); | ||
20 | } | ||
21 | } else { | ||
22 | $token = substr(base64_encode(uniqid(mt_rand(), true)), 0, 20); | ||
23 | } | ||
24 | 17 | ||
25 | // remove character which can broken the url | 18 | // remove character which can broken the url |
26 | return str_replace(array('+', '/'), '', $token); | 19 | return str_replace(array('+', '/'), '', $token); |