Merge pull request #7849 from nextcloud/strict_securerandom
Strict ISecure random
This commit is contained in:
commit
fcea6e1564
|
@ -55,9 +55,9 @@ class TokenHandlerTest extends \Test\TestCase {
|
||||||
$this->expectedTokenLength,
|
$this->expectedTokenLength,
|
||||||
ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_DIGITS
|
ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_DIGITS
|
||||||
)
|
)
|
||||||
->willReturn(true);
|
->willReturn('mytoken');
|
||||||
|
|
||||||
$this->assertTrue($this->tokenHandler->generateToken());
|
$this->assertSame('mytoken', $this->tokenHandler->generateToken());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
/**
|
/**
|
||||||
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
||||||
*
|
*
|
||||||
|
@ -70,9 +71,9 @@ class SecureRandom implements ISecureRandom {
|
||||||
* specified all valid base64 characters are used.
|
* specified all valid base64 characters are used.
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function generate($length,
|
public function generate(int $length,
|
||||||
$characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/') {
|
string $characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'): string {
|
||||||
$maxCharIndex = strlen($characters) - 1;
|
$maxCharIndex = \strlen($characters) - 1;
|
||||||
$randomString = '';
|
$randomString = '';
|
||||||
|
|
||||||
while($length > 0) {
|
while($length > 0) {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
/**
|
/**
|
||||||
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
||||||
*
|
*
|
||||||
|
@ -87,7 +88,7 @@ interface ISecureRandom {
|
||||||
* @return string
|
* @return string
|
||||||
* @since 8.0.0
|
* @since 8.0.0
|
||||||
*/
|
*/
|
||||||
public function generate($length,
|
public function generate(int $length,
|
||||||
$characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/');
|
string $characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'): string;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue