diff --git a/_sakura/components/Configuration.php b/_sakura/components/Configuration.php index 71685c3..89d1294 100644 --- a/_sakura/components/Configuration.php +++ b/_sakura/components/Configuration.php @@ -28,7 +28,11 @@ class Configuration self::$local = $local; } else { // Otherwise trigger an error - trigger_error('Failed to load local configuration file, check the structure of the file to see if you made mistake somewhere', E_USER_ERROR); + trigger_error( + 'Failed to load local configuration file,' . + ' check the structure of the file to see if you made mistake somewhere', + E_USER_ERROR + ); } } @@ -73,7 +77,10 @@ class Configuration } // If it doesn't exist trigger an error to avoid explosions - trigger_error('Unable to get local configuration value "' . $key . '"', E_USER_ERROR); + trigger_error( + 'Unable to get local configuration value "' . $key . '"', + E_USER_ERROR + ); } @@ -111,7 +118,10 @@ class Configuration } // Then return the value - trigger_error('Unable to get configuration value "' . $key . '"', E_USER_ERROR); + trigger_error( + 'Unable to get configuration value "' . $key . '"', + E_USER_ERROR + ); } } diff --git a/_sakura/components/Forum.php b/_sakura/components/Forum.php index 236481b..275e260 100644 --- a/_sakura/components/Forum.php +++ b/_sakura/components/Forum.php @@ -44,12 +44,14 @@ class Forum $return[$forum['forum_category']]['forums'][$forum['forum_id']] = $forum; // Get the topic count - $return[$forum['forum_category']]['forums'][$forum['forum_id']]['topic_count'] = Database::count('topics', [ + $return[$forum['forum_category']]['forums'][$forum['forum_id']]['topic_count'] = + Database::count('topics', [ 'forum_id' => [$forum['forum_id'], '='], ])[0]; // Get the post count - $return[$forum['forum_category']]['forums'][$forum['forum_id']]['post_count'] = Database::count('posts', [ + $return[$forum['forum_category']]['forums'][$forum['forum_id']]['post_count'] = + Database::count('posts', [ 'forum_id' => [$forum['forum_id'], '='], ])[0]; @@ -264,7 +266,12 @@ class Forum 'is_online' => Users::checkUserOnline($_POSTER['id']), 'is_friend' => Users::checkFriend($_POSTER['id']), 'parsed_post' => self::parseMarkUp($post['post_text'], $post['parse_mode'], $post['enable_emotes']), - 'signature' => empty($_POSTER['userData']['signature']) ? '' : self::parseMarkUp($_POSTER['userData']['signature']['text'], $_POSTER['userData']['signature']['mode']), + 'signature' => empty($_POSTER['userData']['signature']) ? + '' : + self::parseMarkUp( + $_POSTER['userData']['signature']['text'], + $_POSTER['userData']['signature']['mode'] + ), ]); // Just in case @@ -328,8 +335,18 @@ class Forum // Collect the stats return [ - 'posts' => Database::count('posts', ['poster_id' => [$uid, '=']])[0], - 'topics' => count(Database::fetch('posts', true, ['poster_id' => [$uid, '=']], ['post_time'], null, ['topic_id'])), + 'posts' => Database::count( + 'posts', + ['poster_id' => [$uid, '=']] + )[0], + 'topics' => Database::count( + 'posts', + true, + ['poster_id' => [$uid, '=']], + ['post_time'], + null, + ['topic_id'] + )[0], ]; } diff --git a/_sakura/components/Hashing.php b/_sakura/components/Hashing.php index a6fbfdb..49238d0 100644 --- a/_sakura/components/Hashing.php +++ b/_sakura/components/Hashing.php @@ -34,43 +34,36 @@ namespace Sakura; class Hashing { // These variables can be changed without break the existing hashes - private static $_PBKDF2_HASH_ALGORITHM = 'sha256'; - private static $_PBKDF2_ITERATIONS = 1000; - private static $_PBKDF2_SALT_BYTES = 24; - private static $_PBKDF2_HASH_BYTES = 24; - - // Changing these will break them though - private static $_HASH_ALGORITHM_INDEX = 0; - private static $_HASH_ITERATION_INDEX = 1; - private static $_HASH_SALT_INDEX = 2; - private static $_HASH_PBKDF2_INDEX = 3; - private static $_HASH_SECTIONS = 4; + private static $hashAlgorithm = 'sha256'; + private static $iterations = 1000; + private static $saltBytes = 24; + private static $hashBytes = 24; // Returns an array formatted like: [algorithm, iterations, salt, hash] - public static function create_hash($pass) + public static function createHash($pass) { $salt = base64_encode( \mcrypt_create_iv( - self::$_PBKDF2_SALT_BYTES, + self::$saltBytes, MCRYPT_DEV_URANDOM ) ); $hash = base64_encode( self::pbkdf2( - self::$_PBKDF2_HASH_ALGORITHM, + self::$hashAlgorithm, $pass, $salt, - self::$_PBKDF2_ITERATIONS, - self::$_PBKDF2_HASH_BYTES, + self::$iterations, + self::$hashBytes, true ) ); $passwordData = array( - self::$_PBKDF2_HASH_ALGORITHM, - self::$_PBKDF2_ITERATIONS, + self::$hashAlgorithm, + self::$iterations, $salt, $hash, ); @@ -80,22 +73,22 @@ class Hashing } // Validates hashed password - public static function validate_password($password, $params) + public static function validatePassword($password, $params) { - if (count($params) < self::$_HASH_SECTIONS) { + if (count($params) < 4) { return false; } - $pbkdf2 = base64_decode($params[self::$_HASH_PBKDF2_INDEX]); + $pbkdf2 = base64_decode($params[3]); - $validate = self::slow_equals( + $validate = self::slowEquals( $pbkdf2, $dick = self::pbkdf2( - $params[self::$_HASH_ALGORITHM_INDEX], + $params[0], $password, - $params[self::$_HASH_SALT_INDEX], - (int) $params[self::$_HASH_ITERATION_INDEX], + $params[2], + (int) $params[1], strlen($pbkdf2), true ) @@ -106,7 +99,7 @@ class Hashing } // Compares two strings $a and $b in length-constant time. - public static function slow_equals($a, $b) + public static function slowEquals($a, $b) { $diff = strlen($a) ^ strlen($b); @@ -141,11 +134,17 @@ class Hashing $algorithm = strtolower($algorithm); if (!in_array($algorithm, hash_algos(), true)) { - trigger_error('PBKDF2 ERROR: Invalid hash algorithm.', E_USER_ERROR); + trigger_error( + 'PBKDF2 ERROR: Invalid hash algorithm.', + E_USER_ERROR + ); } if ($count <= 0 || $key_length <= 0) { - trigger_error('PBKDF2 ERROR: Invalid parameters.', E_USER_ERROR); + trigger_error( + 'PBKDF2 ERROR: Invalid parameters.', + E_USER_ERROR + ); } if (function_exists('hash_pbkdf2')) { diff --git a/_sakura/components/Main.php b/_sakura/components/Main.php index 8028aea..97a3717 100644 --- a/_sakura/components/Main.php +++ b/_sakura/components/Main.php @@ -86,7 +86,11 @@ class Main // Do the replacements foreach ($emotes as $emote) { - $text = str_replace($emote['emote_string'], '' . $emote['emote_string'] . '', $text); + $text = str_replace( + $emote['emote_string'], + '' . $emote['emote_string'] . '', + $text + ); } // Return the parsed text @@ -99,7 +103,12 @@ class Main { // Attempt to get the response - $resp = @file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret=' . Configuration::getConfig('recaptcha_private') . '&response=' . $response); + $resp = @file_get_contents( + 'https://www.google.com/recaptcha/api/siteverify?secret=' + . Configuration::getConfig('recaptcha_private') + . '&response=' + . $response + ); // In the highly unlikely case that it failed to get anything forge a false if (!$resp) { @@ -128,7 +137,12 @@ class Main $backtrace = base64_encode(json_encode(debug_backtrace())); // Check if this error has already been logged in the past - if ($past = Database::fetch('error_log', false, ['backtrace' => [$backtrace, '=', true], 'error_string' => [$errstr, '=']])) { + if ($past = Database::fetch( + 'error_log', + false, + ['backtrace' => [$backtrace, '=', true], + 'error_string' => [$errstr, '=']] + )) { // If so assign the errid $errid = $past['id']; } else { @@ -169,7 +183,8 @@ class Main break; default: - $error = 'Unknown error type [' . $errno . ']: ' . $errstr . ' on line ' . $errline . ' in ' . $errfile; + $error = 'Unknown error type [' . $errno . ']: ' . $errstr . ' on line ' . $errline + . ' in ' . $errfile; } // Truncate all previous outputs @@ -183,13 +198,18 @@ class Main Sakura Internal Error