@@ 49-80 (lines=32) @@ | ||
46 | * @author Anthony Ferrara <[email protected]> |
|
47 | * @codeCoverageIgnore |
|
48 | */ |
|
49 | class MTRand extends \RandomLib\AbstractSource |
|
50 | { |
|
51 | ||
52 | /** |
|
53 | * Return an instance of Strength indicating the strength of the source |
|
54 | * |
|
55 | * @return \SecurityLib\Strength An instance of one of the strength classes |
|
56 | */ |
|
57 | public static function getStrength() |
|
58 | { |
|
59 | // Detect if Suhosin Hardened PHP patch is applied |
|
60 | if (defined('S_ALL')) { |
|
61 | return new Strength(Strength::MEDIUM); |
|
62 | } else { |
|
63 | return new Strength(Strength::LOW); |
|
64 | } |
|
65 | } |
|
66 | ||
67 | /** |
|
68 | * Generate a random string of the specified size |
|
69 | * |
|
70 | * @param int $size The size of the requested random string |
|
71 | * |
|
72 | * @return string A string of the requested size |
|
73 | */ |
|
74 | public function generate($size) |
|
75 | { |
|
76 | $result = ''; |
|
77 | for ($i = 0; $i < $size; $i++) { |
|
78 | $result .= chr((mt_rand() ^ mt_rand()) % 256); |
|
79 | } |
|
80 | ||
81 | return $result; |
|
82 | } |
|
83 | } |
@@ 49-80 (lines=32) @@ | ||
46 | * @author Anthony Ferrara <[email protected]> |
|
47 | * @codeCoverageIgnore |
|
48 | */ |
|
49 | class Rand extends \RandomLib\AbstractSource |
|
50 | { |
|
51 | ||
52 | /** |
|
53 | * Return an instance of Strength indicating the strength of the source |
|
54 | * |
|
55 | * @return \SecurityLib\Strength An instance of one of the strength classes |
|
56 | */ |
|
57 | public static function getStrength() |
|
58 | { |
|
59 | // Detect if Suhosin Hardened PHP patch is applied |
|
60 | if (defined('S_ALL')) { |
|
61 | return new Strength(Strength::LOW); |
|
62 | } else { |
|
63 | return new Strength(Strength::VERYLOW); |
|
64 | } |
|
65 | } |
|
66 | ||
67 | /** |
|
68 | * Generate a random string of the specified size |
|
69 | * |
|
70 | * @param int $size The size of the requested random string |
|
71 | * |
|
72 | * @return string A string of the requested size |
|
73 | */ |
|
74 | public function generate($size) |
|
75 | { |
|
76 | $result = ''; |
|
77 | for ($i = 0; $i < $size; $i++) { |
|
78 | $result .= chr((rand() ^ rand()) % 256); |
|
79 | } |
|
80 | ||
81 | return $result; |
|
82 | } |
|
83 | } |