Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c095fd663f | ||
|
|
7f0987d036 |
@@ -125,11 +125,33 @@ final class CoreLibsCreateRandomKeyTest extends TestCase
|
|||||||
);
|
);
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$expected,
|
$expected,
|
||||||
strlen($random_key),
|
strlen(\CoreLibs\Create\RandomKey::randomKeyGen($input))
|
||||||
'String length not matching'
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check that if set to n and then invalid, it keeps the previous one
|
||||||
|
* or if second change valid, second will be shown
|
||||||
|
*
|
||||||
|
* @covers ::setRandomKeyLength
|
||||||
|
* @dataProvider keepKeyLengthProvider
|
||||||
|
* @testdox keep setRandomKeyLength set with $input_valid and then $input_invalid will be $expected [$_dataName]
|
||||||
|
*
|
||||||
|
* @param integer $input_valid
|
||||||
|
* @param integer $input_invalid
|
||||||
|
* @param integer $expected
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testKeepKeyLength(int $input_valid, int $input_invalid, int $expected): void
|
||||||
|
{
|
||||||
|
\CoreLibs\Create\RandomKey::setRandomKeyLength($input_valid);
|
||||||
|
\CoreLibs\Create\RandomKey::setRandomKeyLength($input_invalid);
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected,
|
||||||
|
\CoreLibs\Create\RandomKey::getRandomKeyLength()
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// __END__
|
// __END__
|
||||||
|
|||||||
@@ -53,6 +53,10 @@ print "===<Br>";
|
|||||||
// CHANGE key characters
|
// CHANGE key characters
|
||||||
$_array = new CoreLibs\Create\RandomKey(['A', 'F', 'B'], ['1', '5', '9']);
|
$_array = new CoreLibs\Create\RandomKey(['A', 'F', 'B'], ['1', '5', '9']);
|
||||||
print "C->RANDOMKEYGEN(pre set): " . $_array->randomKeyGen() . "<br>";
|
print "C->RANDOMKEYGEN(pre set): " . $_array->randomKeyGen() . "<br>";
|
||||||
|
$random_key = new CoreLibs\Create\RandomKey();
|
||||||
|
print "C->RANDOMKEYGEN(auto): " . $random_key->randomKeyGen() . "<br>";
|
||||||
|
$random_key->setRandomKeyCharacters(['a', 'z']);
|
||||||
|
print "C->RANDOMKEYGEN(Fixed set): " . $random_key->randomKeyGen() . "<br>";
|
||||||
|
|
||||||
print "</body></html>";
|
print "</body></html>";
|
||||||
|
|
||||||
|
|||||||
@@ -197,10 +197,8 @@ class Login
|
|||||||
// login html, if we are on an ajax page
|
// login html, if we are on an ajax page
|
||||||
/** @var string|null */
|
/** @var string|null */
|
||||||
private ?string $login_html = '';
|
private ?string $login_html = '';
|
||||||
/** @var bool flag set on run */
|
/** @var bool */
|
||||||
private bool $login_is_ajax_page = false;
|
private bool $login_is_ajax_page = false;
|
||||||
/** @var bool flag set on load */
|
|
||||||
private bool $login_is_ajax_page_option = false;
|
|
||||||
|
|
||||||
// logging
|
// logging
|
||||||
/** @var array<string> list of allowed types for edit log write */
|
/** @var array<string> list of allowed types for edit log write */
|
||||||
@@ -270,6 +268,8 @@ class Login
|
|||||||
}
|
}
|
||||||
// init error array
|
// init error array
|
||||||
$this->loginInitErrorMessages();
|
$this->loginInitErrorMessages();
|
||||||
|
// acess right list
|
||||||
|
$this->loginLoadAccessRightList();
|
||||||
// log allowed write flags
|
// log allowed write flags
|
||||||
$this->loginSetEditLogWriteTypeAvailable();
|
$this->loginSetEditLogWriteTypeAvailable();
|
||||||
|
|
||||||
@@ -342,7 +342,6 @@ class Login
|
|||||||
* locale_path <string>: absolue path to the locale folder
|
* locale_path <string>: absolue path to the locale folder
|
||||||
* site_locale <string>: what locale to load
|
* site_locale <string>: what locale to load
|
||||||
* site_domain <string>: what domain (locale file name) to use
|
* site_domain <string>: what domain (locale file name) to use
|
||||||
* ajax_page <bool>: if we are loading from an AJAX page (eg backend)
|
|
||||||
*
|
*
|
||||||
* @param array<string,mixed> $options Options array from class load
|
* @param array<string,mixed> $options Options array from class load
|
||||||
* @return bool True on ok, False on failure
|
* @return bool True on ok, False on failure
|
||||||
@@ -362,15 +361,6 @@ class Login
|
|||||||
$options['debug'] = false;
|
$options['debug'] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// AUTO LOGIN
|
|
||||||
if (
|
|
||||||
!isset($options['ajax_page']) ||
|
|
||||||
!is_bool($options['ajax_page'])
|
|
||||||
) {
|
|
||||||
$options['ajax_page'] = false;
|
|
||||||
}
|
|
||||||
$this->login_is_ajax_page_option = $options['ajax_page'];
|
|
||||||
|
|
||||||
// AUTO LOGIN
|
// AUTO LOGIN
|
||||||
if (
|
if (
|
||||||
!isset($options['auto_login']) ||
|
!isset($options['auto_login']) ||
|
||||||
@@ -701,34 +691,6 @@ class Login
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* get the default ACL list type
|
|
||||||
* if not set loads it from DB
|
|
||||||
*
|
|
||||||
* @return array<string,int>
|
|
||||||
*/
|
|
||||||
private function loginGetAccessRightListType(): array
|
|
||||||
{
|
|
||||||
if (empty($this->default_acl_list_type)) {
|
|
||||||
$this->loginLoadAccessRightList();
|
|
||||||
}
|
|
||||||
return $this->default_acl_list_type;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get the default ACL list
|
|
||||||
* if not set loads from DB
|
|
||||||
*
|
|
||||||
* @return array<string|int, mixed>
|
|
||||||
*/
|
|
||||||
private function loginGetAccessRightList(): array
|
|
||||||
{
|
|
||||||
if (empty($this->default_acl_list)) {
|
|
||||||
$this->loginLoadAccessRightList();
|
|
||||||
}
|
|
||||||
return $this->default_acl_list;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Improves the application's security over HTTP(S) by setting specific headers
|
* Improves the application's security over HTTP(S) by setting specific headers
|
||||||
*
|
*
|
||||||
@@ -1578,10 +1540,6 @@ class Login
|
|||||||
$this->acl['unit'] = [];
|
$this->acl['unit'] = [];
|
||||||
$this->acl['unit_legacy'] = [];
|
$this->acl['unit_legacy'] = [];
|
||||||
$this->acl['unit_detail'] = [];
|
$this->acl['unit_detail'] = [];
|
||||||
// integrate the type acl list, but only for the keyword -> level
|
|
||||||
$this->acl['min'] = $this->loginGetAccessRightListType();
|
|
||||||
// set the full acl list too (lookup level number and get level data)
|
|
||||||
$this->acl['acl_list'] = $this->loginGetAccessRightList();
|
|
||||||
|
|
||||||
// PER ACCOUNT (UNIT/edit access)->
|
// PER ACCOUNT (UNIT/edit access)->
|
||||||
foreach ($_SESSION['LOGIN_UNIT'] as $ea_cuid => $unit) {
|
foreach ($_SESSION['LOGIN_UNIT'] as $ea_cuid => $unit) {
|
||||||
@@ -1603,7 +1561,7 @@ class Login
|
|||||||
'name' => $unit['name'],
|
'name' => $unit['name'],
|
||||||
'uid' => $unit['uid'],
|
'uid' => $unit['uid'],
|
||||||
'cuuid' => $unit['cuuid'],
|
'cuuid' => $unit['cuuid'],
|
||||||
'level' => $this->acl['acl_list'][$this->acl['unit'][$ea_cuid]]['name'] ?? -1,
|
'level' => $this->default_acl_list[$this->acl['unit'][$ea_cuid]]['name'] ?? -1,
|
||||||
'level_number' => $this->acl['unit'][$ea_cuid],
|
'level_number' => $this->acl['unit'][$ea_cuid],
|
||||||
'default' => $unit['default'],
|
'default' => $unit['default'],
|
||||||
'data' => $unit['data'],
|
'data' => $unit['data'],
|
||||||
@@ -1624,6 +1582,10 @@ class Login
|
|||||||
}
|
}
|
||||||
// set the default edit access
|
// set the default edit access
|
||||||
$this->acl['default_edit_access'] = $_SESSION['LOGIN_UNIT_DEFAULT_EACUID'];
|
$this->acl['default_edit_access'] = $_SESSION['LOGIN_UNIT_DEFAULT_EACUID'];
|
||||||
|
// integrate the type acl list, but only for the keyword -> level
|
||||||
|
$this->acl['min'] = $this->default_acl_list_type;
|
||||||
|
// set the full acl list too (lookup level number and get level data)
|
||||||
|
$this->acl['acl_list'] = $this->default_acl_list;
|
||||||
// debug
|
// debug
|
||||||
// $this->debug('ACL', $this->print_ar($this->acl));
|
// $this->debug('ACL', $this->print_ar($this->acl));
|
||||||
}
|
}
|
||||||
@@ -2557,12 +2519,7 @@ HTML;
|
|||||||
// or need to pass it back
|
// or need to pass it back
|
||||||
// to the continue AJAX class for output back to the user
|
// to the continue AJAX class for output back to the user
|
||||||
$this->login_is_ajax_page = false;
|
$this->login_is_ajax_page = false;
|
||||||
if (
|
if ($ajax_page === true || !empty($GLOBALS['AJAX_PAGE'])) {
|
||||||
$ajax_page === true ||
|
|
||||||
$this->login_is_ajax_page_option == true ||
|
|
||||||
// this is deprecated
|
|
||||||
!empty($GLOBALS['AJAX_PAGE'])
|
|
||||||
) {
|
|
||||||
$this->login_is_ajax_page = true;
|
$this->login_is_ajax_page = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3190,8 +3147,6 @@ HTML;
|
|||||||
*/
|
*/
|
||||||
public function loginGetAclList(?int $level = null): array
|
public function loginGetAclList(?int $level = null): array
|
||||||
{
|
{
|
||||||
// make sure it is loaded
|
|
||||||
$this->loginGetAccessRightList();
|
|
||||||
// if no level given, return full list
|
// if no level given, return full list
|
||||||
if (empty($level)) {
|
if (empty($level)) {
|
||||||
return $this->default_acl_list;
|
return $this->default_acl_list;
|
||||||
@@ -3214,9 +3169,6 @@ HTML;
|
|||||||
*/
|
*/
|
||||||
public function loginGetAclListFromType(string $type): int|bool
|
public function loginGetAclListFromType(string $type): int|bool
|
||||||
{
|
{
|
||||||
// make sure it is loaded
|
|
||||||
$this->loginGetAccessRightListType();
|
|
||||||
// if not et return false
|
|
||||||
if (!isset($this->default_acl_list_type[$type])) {
|
if (!isset($this->default_acl_list_type[$type])) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -119,6 +119,32 @@ class RandomKey
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sets a different character range
|
||||||
|
*
|
||||||
|
* @param array<array{0:string,1:string}> $ranges
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function setRandomKeyCharacters(array ...$ranges): bool
|
||||||
|
{
|
||||||
|
// each range must be an arary of start end range
|
||||||
|
$character_range = [];
|
||||||
|
foreach ($ranges as $range) {
|
||||||
|
if (count($range) != 2) {
|
||||||
|
throw new \ArgumentCountError(__FUNCTION__ . ' array must have two range entries');
|
||||||
|
}
|
||||||
|
$character_range = array_merge($character_range, range($range[0], $range[1]));
|
||||||
|
}
|
||||||
|
self::$key_range = join('', $character_range);
|
||||||
|
self::$one_key_length = strlen(self::$key_range);
|
||||||
|
if (
|
||||||
|
self::$one_key_length == 0
|
||||||
|
) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* sets the key length and checks that they key given is valid
|
* sets the key length and checks that they key given is valid
|
||||||
* if failed it will not change the default key length and return false
|
* if failed it will not change the default key length and return false
|
||||||
|
|||||||
Reference in New Issue
Block a user