Skip to content

Commit

Permalink
Bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
viames committed Oct 10, 2023
1 parent fca033e commit 702588c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/ActiveRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ public function __call(string $name, array $arguments) {
$multiPairClass = 'Pair\\' . $multiClass;

// maybe call is referring to
if ('get'==substr($name,0,3)) {
if ($this->areKeysPopulated() and 'get'==substr($name,0,3)) {

// check if invoked a virtual method on Pair class
if (class_exists($evenPairClass) and is_subclass_of($evenPairClass,'Pair\ActiveRecord')) {
Expand Down
2 changes: 1 addition & 1 deletion src/UserRemember.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public static function getCookieContent(): ?\stdClass {
return NULL;
}

$regex = "#^[123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVXYWZ]{32}$#";
$regex = '#^[' . Utilities::RANDOM_STRING_CHARS . ']{32}$#';

// check if content exists and RememberMe length
if (is_array($content) and isset($content[0]) and isset($content[1]) and preg_match($regex, (string)$content[1])) {
Expand Down
10 changes: 6 additions & 4 deletions src/Utilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
*/
class Utilities {

/**
* List of characters allowed for the composition of a random string.
*/
const RANDOM_STRING_CHARS = '123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';

/**
* Custom error handler.
*
Expand Down Expand Up @@ -992,11 +997,8 @@ public static function getFileUrl($filePath, $addTimestamp = FALSE) {
*/
public static function getRandomString(int $length): string {

// list of available chars for random string
$availableChars = '123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVXYWZ';

// create a random string
return substr(str_shuffle($availableChars . $availableChars), 0, $length);
return substr(str_shuffle(self::RANDOM_STRING_CHARS . self::RANDOM_STRING_CHARS), 0, $length);

}

Expand Down

0 comments on commit 702588c

Please sign in to comment.