@@ -39,28 +39,28 @@ |
||
| 39 | 39 | * @package OC\Security |
| 40 | 40 | */ |
| 41 | 41 | class SecureRandom implements ISecureRandom { |
| 42 | - /** |
|
| 43 | - * Generate a secure random string of specified length. |
|
| 44 | - * @param int $length The length of the generated string |
|
| 45 | - * @param string $characters An optional list of characters to use if no character list is |
|
| 46 | - * specified all valid base64 characters are used. |
|
| 47 | - * @return string |
|
| 48 | - * @throws \LengthException if an invalid length is requested |
|
| 49 | - */ |
|
| 50 | - public function generate(int $length, |
|
| 51 | - string $characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'): string { |
|
| 52 | - if ($length <= 0) { |
|
| 53 | - throw new \LengthException('Invalid length specified: ' . $length . ' must be bigger than 0'); |
|
| 54 | - } |
|
| 42 | + /** |
|
| 43 | + * Generate a secure random string of specified length. |
|
| 44 | + * @param int $length The length of the generated string |
|
| 45 | + * @param string $characters An optional list of characters to use if no character list is |
|
| 46 | + * specified all valid base64 characters are used. |
|
| 47 | + * @return string |
|
| 48 | + * @throws \LengthException if an invalid length is requested |
|
| 49 | + */ |
|
| 50 | + public function generate(int $length, |
|
| 51 | + string $characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'): string { |
|
| 52 | + if ($length <= 0) { |
|
| 53 | + throw new \LengthException('Invalid length specified: ' . $length . ' must be bigger than 0'); |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - $maxCharIndex = \strlen($characters) - 1; |
|
| 57 | - $randomString = ''; |
|
| 56 | + $maxCharIndex = \strlen($characters) - 1; |
|
| 57 | + $randomString = ''; |
|
| 58 | 58 | |
| 59 | - while ($length > 0) { |
|
| 60 | - $randomNumber = \random_int(0, $maxCharIndex); |
|
| 61 | - $randomString .= $characters[$randomNumber]; |
|
| 62 | - $length--; |
|
| 63 | - } |
|
| 64 | - return $randomString; |
|
| 65 | - } |
|
| 59 | + while ($length > 0) { |
|
| 60 | + $randomNumber = \random_int(0, $maxCharIndex); |
|
| 61 | + $randomString .= $characters[$randomNumber]; |
|
| 62 | + $length--; |
|
| 63 | + } |
|
| 64 | + return $randomString; |
|
| 65 | + } |
|
| 66 | 66 | } |
@@ -50,7 +50,7 @@ |
||
| 50 | 50 | public function generate(int $length, |
| 51 | 51 | string $characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'): string { |
| 52 | 52 | if ($length <= 0) { |
| 53 | - throw new \LengthException('Invalid length specified: ' . $length . ' must be bigger than 0'); |
|
| 53 | + throw new \LengthException('Invalid length specified: '.$length.' must be bigger than 0'); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | $maxCharIndex = \strlen($characters) - 1; |