Chris@76: 0, $array[3] & 2 > 0); Chris@76: setcookie($cookiename, serialize(array(0, '', 0)), time() - 3600, $cookie_url[1], $cookie_url[0], !empty($modSettings['secureCookies'])); Chris@76: } Chris@76: } Chris@76: Chris@76: // Get the data and path to set it on. Chris@76: $data = serialize(empty($id) ? array(0, '', 0) : array($id, $password, time() + $cookie_length, $cookie_state)); Chris@76: $cookie_url = url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies'])); Chris@76: Chris@76: // Set the cookie, $_COOKIE, and session variable. Chris@76: setcookie($cookiename, $data, time() + $cookie_length, $cookie_url[1], $cookie_url[0], !empty($modSettings['secureCookies'])); Chris@76: Chris@76: // If subdomain-independent cookies are on, unset the subdomain-dependent cookie too. Chris@76: if (empty($id) && !empty($modSettings['globalCookies'])) Chris@76: setcookie($cookiename, $data, time() + $cookie_length, $cookie_url[1], '', !empty($modSettings['secureCookies'])); Chris@76: Chris@76: // Any alias URLs? This is mainly for use with frames, etc. Chris@76: if (!empty($modSettings['forum_alias_urls'])) Chris@76: { Chris@76: $aliases = explode(',', $modSettings['forum_alias_urls']); Chris@76: Chris@76: $temp = $boardurl; Chris@76: foreach ($aliases as $alias) Chris@76: { Chris@76: // Fake the $boardurl so we can set a different cookie. Chris@76: $alias = strtr(trim($alias), array('http://' => '', 'https://' => '')); Chris@76: $boardurl = 'http://' . $alias; Chris@76: Chris@76: $cookie_url = url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies'])); Chris@76: Chris@76: if ($cookie_url[0] == '') Chris@76: $cookie_url[0] = strtok($alias, '/'); Chris@76: Chris@76: setcookie($cookiename, $data, time() + $cookie_length, $cookie_url[1], $cookie_url[0], !empty($modSettings['secureCookies'])); Chris@76: } Chris@76: Chris@76: $boardurl = $temp; Chris@76: } Chris@76: Chris@76: $_COOKIE[$cookiename] = $data; Chris@76: Chris@76: // Make sure the user logs in with a new session ID. Chris@76: if (!isset($_SESSION['login_' . $cookiename]) || $_SESSION['login_' . $cookiename] !== $data) Chris@76: { Chris@76: // Backup and remove the old session. Chris@76: $oldSessionData = $_SESSION; Chris@76: $_SESSION = array(); Chris@76: session_destroy(); Chris@76: Chris@76: // Recreate and restore the new session. Chris@76: loadSession(); Chris@76: session_regenerate_id(); Chris@76: $_SESSION = $oldSessionData; Chris@76: Chris@76: // Version 4.3.2 didn't store the cookie of the new session. Chris@76: if (version_compare(PHP_VERSION, '4.3.2') === 0) Chris@76: { Chris@76: $sessionCookieLifetime = @ini_get('session.cookie_lifetime'); Chris@76: setcookie(session_name(), session_id(), time() + (empty($sessionCookieLifetime) ? $cookie_length : $sessionCookieLifetime), $cookie_url[1], $cookie_url[0], !empty($modSettings['secureCookies'])); Chris@76: } Chris@76: Chris@76: $_SESSION['login_' . $cookiename] = $data; Chris@76: } Chris@76: } Chris@76: Chris@76: // PHP < 4.3.2 doesn't have this function Chris@76: if (!function_exists('session_regenerate_id')) Chris@76: { Chris@76: function session_regenerate_id() Chris@76: { Chris@76: // Too late to change the session now. Chris@76: if (headers_sent()) Chris@76: return false; Chris@76: Chris@76: session_id(strtolower(md5(uniqid(mt_rand(), true)))); Chris@76: return true; Chris@76: } Chris@76: Chris@76: } Chris@76: Chris@76: // Get the domain and path for the cookie... Chris@76: function url_parts($local, $global) Chris@76: { Chris@76: global $boardurl; Chris@76: Chris@76: // Parse the URL with PHP to make life easier. Chris@76: $parsed_url = parse_url($boardurl); Chris@76: Chris@76: // Is local cookies off? Chris@76: if (empty($parsed_url['path']) || !$local) Chris@76: $parsed_url['path'] = ''; Chris@76: Chris@76: // Globalize cookies across domains (filter out IP-addresses)? Chris@76: if ($global && preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 && preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) == 1) Chris@76: $parsed_url['host'] = '.' . $parts[1]; Chris@76: Chris@76: // We shouldn't use a host at all if both options are off. Chris@76: elseif (!$local && !$global) Chris@76: $parsed_url['host'] = ''; Chris@76: Chris@76: // The host also shouldn't be set if there aren't any dots in it. Chris@76: elseif (!isset($parsed_url['host']) || strpos($parsed_url['host'], '.') === false) Chris@76: $parsed_url['host'] = ''; Chris@76: Chris@76: return array($parsed_url['host'], $parsed_url['path'] . '/'); Chris@76: } Chris@76: Chris@76: // Kick out a guest when guest access is off... Chris@76: function KickGuest() Chris@76: { Chris@76: global $txt, $context; Chris@76: Chris@76: loadLanguage('Login'); Chris@76: loadTemplate('Login'); Chris@76: Chris@76: // Never redirect to an attachment Chris@76: if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false) Chris@76: $_SESSION['login_url'] = $_SERVER['REQUEST_URL']; Chris@76: Chris@76: $context['sub_template'] = 'kick_guest'; Chris@76: $context['page_title'] = $txt['login']; Chris@76: } Chris@76: Chris@76: // Display a message about the forum being in maintenance mode, etc. Chris@76: function InMaintenance() Chris@76: { Chris@76: global $txt, $mtitle, $mmessage, $context; Chris@76: Chris@76: loadLanguage('Login'); Chris@76: loadTemplate('Login'); Chris@76: Chris@76: // Send a 503 header, so search engines don't bother indexing while we're in maintenance mode. Chris@76: header('HTTP/1.1 503 Service Temporarily Unavailable'); Chris@76: Chris@76: // Basic template stuff.. Chris@76: $context['sub_template'] = 'maintenance'; Chris@76: $context['title'] = &$mtitle; Chris@76: $context['description'] = &$mmessage; Chris@76: $context['page_title'] = $txt['maintain_mode']; Chris@76: } Chris@76: Chris@76: function adminLogin() Chris@76: { Chris@76: global $context, $scripturl, $txt, $user_info, $user_settings; Chris@76: Chris@76: loadLanguage('Admin'); Chris@76: loadTemplate('Login'); Chris@76: Chris@76: // They used a wrong password, log it and unset that. Chris@76: if (isset($_POST['admin_hash_pass']) || isset($_POST['admin_pass'])) Chris@76: { Chris@76: $txt['security_wrong'] = sprintf($txt['security_wrong'], isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : $txt['unknown'], $_SERVER['HTTP_USER_AGENT'], $user_info['ip']); Chris@76: log_error($txt['security_wrong'], 'critical'); Chris@76: Chris@76: if (isset($_POST['admin_hash_pass'])) Chris@76: unset($_POST['admin_hash_pass']); Chris@76: if (isset($_POST['admin_pass'])) Chris@76: unset($_POST['admin_pass']); Chris@76: Chris@76: $context['incorrect_password'] = true; Chris@76: } Chris@76: Chris@76: // Figure out the get data and post data. Chris@76: $context['get_data'] = '?' . construct_query_string($_GET); Chris@76: $context['post_data'] = ''; Chris@76: Chris@76: // Now go through $_POST. Make sure the session hash is sent. Chris@76: $_POST[$context['session_var']] = $context['session_id']; Chris@76: foreach ($_POST as $k => $v) Chris@76: $context['post_data'] .= adminLogin_outputPostVars($k, $v); Chris@76: Chris@76: // Now we'll use the admin_login sub template of the Login template. Chris@76: $context['sub_template'] = 'admin_login'; Chris@76: Chris@76: // And title the page something like "Login". Chris@76: if (!isset($context['page_title'])) Chris@76: $context['page_title'] = $txt['login']; Chris@76: Chris@76: obExit(); Chris@76: Chris@76: // We MUST exit at this point, because otherwise we CANNOT KNOW that the user is privileged. Chris@76: trigger_error('Hacking attempt...', E_USER_ERROR); Chris@76: } Chris@76: Chris@76: function adminLogin_outputPostVars($k, $v) Chris@76: { Chris@76: global $smcFunc; Chris@76: Chris@76: if (!is_array($v)) Chris@76: return ' Chris@76: '"', '<' => '<', '>' => '>')) . '" />'; Chris@76: else Chris@76: { Chris@76: $ret = ''; Chris@76: foreach ($v as $k2 => $v2) Chris@76: $ret .= adminLogin_outputPostVars($k . '[' . $k2 . ']', $v2); Chris@76: Chris@76: return $ret; Chris@76: } Chris@76: } Chris@76: Chris@76: function construct_query_string($get) Chris@76: { Chris@76: global $scripturl; Chris@76: Chris@76: $query_string = ''; Chris@76: Chris@76: // Awww, darn. The $scripturl contains GET stuff! Chris@76: $q = strpos($scripturl, '?'); Chris@76: if ($q !== false) Chris@76: { Chris@76: parse_str(preg_replace('/&(\w+)(?=&|$)/', '&$1=', strtr(substr($scripturl, $q + 1), ';', '&')), $temp); Chris@76: Chris@76: foreach ($get as $k => $v) Chris@76: { Chris@76: // Only if it's not already in the $scripturl! Chris@76: if (!isset($temp[$k])) Chris@76: $query_string .= urlencode($k) . '=' . urlencode($v) . ';'; Chris@76: // If it changed, put it out there, but with an ampersand. Chris@76: elseif ($temp[$k] != $get[$k]) Chris@76: $query_string .= urlencode($k) . '=' . urlencode($v) . '&'; Chris@76: } Chris@76: } Chris@76: else Chris@76: { Chris@76: // Add up all the data from $_GET into get_data. Chris@76: foreach ($get as $k => $v) Chris@76: $query_string .= urlencode($k) . '=' . urlencode($v) . ';'; Chris@76: } Chris@76: Chris@76: $query_string = substr($query_string, 0, -1); Chris@76: return $query_string; Chris@76: } Chris@76: Chris@76: // Find members by email address, username, or real name. Chris@76: function findMembers($names, $use_wildcards = false, $buddies_only = false, $max = 500) Chris@76: { Chris@76: global $scripturl, $user_info, $modSettings, $smcFunc; Chris@76: Chris@76: // If it's not already an array, make it one. Chris@76: if (!is_array($names)) Chris@76: $names = explode(',', $names); Chris@76: Chris@76: $maybe_email = false; Chris@76: foreach ($names as $i => $name) Chris@76: { Chris@76: // Trim, and fix wildcards for each name. Chris@76: $names[$i] = trim($smcFunc['strtolower']($name)); Chris@76: Chris@76: $maybe_email |= strpos($name, '@') !== false; Chris@76: Chris@76: // Make it so standard wildcards will work. (* and ?) Chris@76: if ($use_wildcards) Chris@76: $names[$i] = strtr($names[$i], array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_', '\'' => ''')); Chris@76: else Chris@76: $names[$i] = strtr($names[$i], array('\'' => ''')); Chris@76: } Chris@76: Chris@76: // What are we using to compare? Chris@76: $comparison = $use_wildcards ? 'LIKE' : '='; Chris@76: Chris@76: // Nothing found yet. Chris@76: $results = array(); Chris@76: Chris@76: // This ensures you can't search someones email address if you can't see it. Chris@76: $email_condition = allowedTo('moderate_forum') ? '' : 'hide_email = 0 AND '; Chris@76: Chris@76: if ($use_wildcards || $maybe_email) Chris@76: $email_condition = ' Chris@76: OR (' . $email_condition . 'email_address ' . $comparison . ' \'' . implode( '\') OR (' . $email_condition . ' email_address ' . $comparison . ' \'', $names) . '\')'; Chris@76: else Chris@76: $email_condition = ''; Chris@76: Chris@76: // Get the case of the columns right - but only if we need to as things like MySQL will go slow needlessly otherwise. Chris@76: $member_name = $smcFunc['db_case_sensitive'] ? 'LOWER(member_name)' : 'member_name'; Chris@76: $real_name = $smcFunc['db_case_sensitive'] ? 'LOWER(real_name)' : 'real_name'; Chris@76: Chris@76: // Search by username, display name, and email address. Chris@76: $request = $smcFunc['db_query']('', ' Chris@76: SELECT id_member, member_name, real_name, email_address, hide_email Chris@76: FROM {db_prefix}members Chris@76: WHERE ({raw:member_name_search} Chris@76: OR {raw:real_name_search} {raw:email_condition}) Chris@76: ' . ($buddies_only ? 'AND id_member IN ({array_int:buddy_list})' : '') . ' Chris@76: AND is_activated IN (1, 11) Chris@76: LIMIT {int:limit}', Chris@76: array( Chris@76: 'buddy_list' => $user_info['buddies'], Chris@76: 'member_name_search' => $member_name . ' ' . $comparison . ' \'' . implode( '\' OR ' . $member_name . ' ' . $comparison . ' \'', $names) . '\'', Chris@76: 'real_name_search' => $real_name . ' ' . $comparison . ' \'' . implode( '\' OR ' . $real_name . ' ' . $comparison . ' \'', $names) . '\'', Chris@76: 'email_condition' => $email_condition, Chris@76: 'limit' => $max, Chris@76: ) Chris@76: ); Chris@76: while ($row = $smcFunc['db_fetch_assoc']($request)) Chris@76: { Chris@76: $results[$row['id_member']] = array( Chris@76: 'id' => $row['id_member'], Chris@76: 'name' => $row['real_name'], Chris@76: 'username' => $row['member_name'], Chris@76: 'email' => in_array(showEmailAddress(!empty($row['hide_email']), $row['id_member']), array('yes', 'yes_permission_override')) ? $row['email_address'] : '', Chris@76: 'href' => $scripturl . '?action=profile;u=' . $row['id_member'], Chris@76: 'link' => '' . $row['real_name'] . '' Chris@76: ); Chris@76: } Chris@76: $smcFunc['db_free_result']($request); Chris@76: Chris@76: // Return all the results. Chris@76: return $results; Chris@76: } Chris@76: Chris@76: function JSMembers() Chris@76: { Chris@76: global $context, $scripturl, $user_info, $smcFunc; Chris@76: Chris@76: checkSession('get'); Chris@76: Chris@76: if (WIRELESS) Chris@76: $context['sub_template'] = WIRELESS_PROTOCOL . '_pm'; Chris@76: else Chris@76: { Chris@76: // Why is this in the Help template, you ask? Well, erm... it helps you. Does that work? Chris@76: loadTemplate('Help'); Chris@76: Chris@76: $context['template_layers'] = array(); Chris@76: $context['sub_template'] = 'find_members'; Chris@76: } Chris@76: Chris@76: if (isset($_REQUEST['search'])) Chris@76: $context['last_search'] = $smcFunc['htmlspecialchars']($_REQUEST['search'], ENT_QUOTES); Chris@76: else Chris@76: $_REQUEST['start'] = 0; Chris@76: Chris@76: // Allow the user to pass the input to be added to to the box. Chris@76: $context['input_box_name'] = isset($_REQUEST['input']) && preg_match('~^[\w-]+$~', $_REQUEST['input']) === 1 ? $_REQUEST['input'] : 'to'; Chris@76: Chris@76: // Take the delimiter over GET in case it's \n or something. Chris@76: $context['delimiter'] = isset($_REQUEST['delim']) ? ($_REQUEST['delim'] == 'LB' ? "\n" : $_REQUEST['delim']) : ', '; Chris@76: $context['quote_results'] = !empty($_REQUEST['quote']); Chris@76: Chris@76: // List all the results. Chris@76: $context['results'] = array(); Chris@76: Chris@76: // Some buddy related settings ;) Chris@76: $context['show_buddies'] = !empty($user_info['buddies']); Chris@76: $context['buddy_search'] = isset($_REQUEST['buddies']); Chris@76: Chris@76: // If the user has done a search, well - search. Chris@76: if (isset($_REQUEST['search'])) Chris@76: { Chris@76: $_REQUEST['search'] = $smcFunc['htmlspecialchars']($_REQUEST['search'], ENT_QUOTES); Chris@76: Chris@76: $context['results'] = findMembers(array($_REQUEST['search']), true, $context['buddy_search']); Chris@76: $total_results = count($context['results']); Chris@76: Chris@76: $context['page_index'] = constructPageIndex($scripturl . '?action=findmember;search=' . $context['last_search'] . ';' . $context['session_var'] . '=' . $context['session_id'] . ';input=' . $context['input_box_name'] . ($context['quote_results'] ? ';quote=1' : '') . ($context['buddy_search'] ? ';buddies' : ''), $_REQUEST['start'], $total_results, 7); Chris@76: Chris@76: // Determine the navigation context (especially useful for the wireless template). Chris@76: $base_url = $scripturl . '?action=findmember;search=' . urlencode($context['last_search']) . (empty($_REQUEST['u']) ? '' : ';u=' . $_REQUEST['u']) . ';' . $context['session_var'] . '=' . $context['session_id']; Chris@76: $context['links'] = array( Chris@76: 'first' => $_REQUEST['start'] >= 7 ? $base_url . ';start=0' : '', Chris@76: 'prev' => $_REQUEST['start'] >= 7 ? $base_url . ';start=' . ($_REQUEST['start'] - 7) : '', Chris@76: 'next' => $_REQUEST['start'] + 7 < $total_results ? $base_url . ';start=' . ($_REQUEST['start'] + 7) : '', Chris@76: 'last' => $_REQUEST['start'] + 7 < $total_results ? $base_url . ';start=' . (floor(($total_results - 1) / 7) * 7) : '', Chris@76: 'up' => $scripturl . '?action=pm;sa=send' . (empty($_REQUEST['u']) ? '' : ';u=' . $_REQUEST['u']), Chris@76: ); Chris@76: $context['page_info'] = array( Chris@76: 'current_page' => $_REQUEST['start'] / 7 + 1, Chris@76: 'num_pages' => floor(($total_results - 1) / 7) + 1 Chris@76: ); Chris@76: Chris@76: $context['results'] = array_slice($context['results'], $_REQUEST['start'], 7); Chris@76: } Chris@76: else Chris@76: $context['links']['up'] = $scripturl . '?action=pm;sa=send' . (empty($_REQUEST['u']) ? '' : ';u=' . $_REQUEST['u']); Chris@76: } Chris@76: Chris@76: function RequestMembers() Chris@76: { Chris@76: global $user_info, $txt, $smcFunc; Chris@76: Chris@76: checkSession('get'); Chris@76: Chris@76: $_REQUEST['search'] = $smcFunc['htmlspecialchars']($_REQUEST['search']) . '*'; Chris@76: $_REQUEST['search'] = trim($smcFunc['strtolower']($_REQUEST['search'])); Chris@76: $_REQUEST['search'] = strtr($_REQUEST['search'], array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_', '&' => '&')); Chris@76: Chris@76: if (function_exists('iconv')) Chris@76: header('Content-Type: text/plain; charset=UTF-8'); Chris@76: Chris@76: $request = $smcFunc['db_query']('', ' Chris@76: SELECT real_name Chris@76: FROM {db_prefix}members Chris@76: WHERE real_name LIKE {string:search}' . (isset($_REQUEST['buddies']) ? ' Chris@76: AND id_member IN ({array_int:buddy_list})' : '') . ' Chris@76: AND is_activated IN (1, 11) Chris@76: LIMIT ' . ($smcFunc['strlen']($_REQUEST['search']) <= 2 ? '100' : '800'), Chris@76: array( Chris@76: 'buddy_list' => $user_info['buddies'], Chris@76: 'search' => $_REQUEST['search'], Chris@76: ) Chris@76: ); Chris@76: while ($row = $smcFunc['db_fetch_assoc']($request)) Chris@76: { Chris@76: if (function_exists('iconv')) Chris@76: { Chris@76: $utf8 = iconv($txt['lang_character_set'], 'UTF-8', $row['real_name']); Chris@76: if ($utf8) Chris@76: $row['real_name'] = $utf8; Chris@76: } Chris@76: Chris@76: $row['real_name'] = strtr($row['real_name'], array('&' => '&', '<' => '<', '>' => '>', '"' => '"')); Chris@76: Chris@76: if (preg_match('~&#\d+;~', $row['real_name']) != 0) Chris@76: { Chris@76: $fixchar = create_function('$n', ' Chris@76: if ($n < 128) Chris@76: return chr($n); Chris@76: elseif ($n < 2048) Chris@76: return chr(192 | $n >> 6) . chr(128 | $n & 63); Chris@76: elseif ($n < 65536) Chris@76: return chr(224 | $n >> 12) . chr(128 | $n >> 6 & 63) . chr(128 | $n & 63); Chris@76: else Chris@76: return chr(240 | $n >> 18) . chr(128 | $n >> 12 & 63) . chr(128 | $n >> 6 & 63) . chr(128 | $n & 63);'); Chris@76: Chris@76: $row['real_name'] = preg_replace('~&#(\d+);~e', '$fixchar(\'$1\')', $row['real_name']); Chris@76: } Chris@76: Chris@76: echo $row['real_name'], "\n"; Chris@76: } Chris@76: $smcFunc['db_free_result']($request); Chris@76: Chris@76: obExit(false); Chris@76: } Chris@76: Chris@76: // This function generates a random password for a user and emails it to them. Chris@76: function resetPassword($memID, $username = null) Chris@76: { Chris@76: global $scripturl, $context, $txt, $sourcedir, $modSettings, $smcFunc, $language; Chris@76: Chris@76: // Language... and a required file. Chris@76: loadLanguage('Login'); Chris@76: require_once($sourcedir . '/Subs-Post.php'); Chris@76: Chris@76: // Get some important details. Chris@76: $request = $smcFunc['db_query']('', ' Chris@76: SELECT member_name, email_address, lngfile Chris@76: FROM {db_prefix}members Chris@76: WHERE id_member = {int:id_member}', Chris@76: array( Chris@76: 'id_member' => $memID, Chris@76: ) Chris@76: ); Chris@76: list ($user, $email, $lngfile) = $smcFunc['db_fetch_row']($request); Chris@76: $smcFunc['db_free_result']($request); Chris@76: Chris@76: if ($username !== null) Chris@76: { Chris@76: $old_user = $user; Chris@76: $user = trim($username); Chris@76: } Chris@76: Chris@76: // Generate a random password. Chris@76: $newPassword = substr(preg_replace('/\W/', '', md5(mt_rand())), 0, 10); Chris@76: $newPassword_sha1 = sha1(strtolower($user) . $newPassword); Chris@76: Chris@76: // Do some checks on the username if needed. Chris@76: if ($username !== null) Chris@76: { Chris@76: validateUsername($memID, $user); Chris@76: Chris@76: // Update the database... Chris@76: updateMemberData($memID, array('member_name' => $user, 'passwd' => $newPassword_sha1)); Chris@76: } Chris@76: else Chris@76: updateMemberData($memID, array('passwd' => $newPassword_sha1)); Chris@76: Chris@76: call_integration_hook('integrate_reset_pass', array($old_user, $user, $newPassword)); Chris@76: Chris@76: $replacements = array( Chris@76: 'USERNAME' => $user, Chris@76: 'PASSWORD' => $newPassword, Chris@76: ); Chris@76: Chris@76: $emaildata = loadEmailTemplate('change_password', $replacements, empty($lngfile) || empty($modSettings['userLanguage']) ? $language : $lngfile); Chris@76: Chris@76: // Send them the email informing them of the change - then we're done! Chris@76: sendmail($email, $emaildata['subject'], $emaildata['body'], null, null, false, 0); Chris@76: } Chris@76: Chris@76: // Is this a valid username? Chris@76: function validateUsername($memID, $username) Chris@76: { Chris@76: global $sourcedir, $txt; Chris@76: Chris@76: // No name?! How can you register with no name? Chris@76: if ($username == '') Chris@76: fatal_lang_error('need_username', false); Chris@76: Chris@76: // Only these characters are permitted. Chris@76: if (in_array($username, array('_', '|')) || preg_match('~[<>&"\'=\\\\]~', preg_replace('~&#(?:\\d{1,7}|x[0-9a-fA-F]{1,6});~', '', $username)) != 0 || strpos($username, '[code') !== false || strpos($username, '[/code') !== false) Chris@76: fatal_lang_error('error_invalid_characters_username', false); Chris@76: Chris@76: if (stristr($username, $txt['guest_title']) !== false) Chris@76: fatal_lang_error('username_reserved', true, array($txt['guest_title'])); Chris@76: Chris@76: require_once($sourcedir . '/Subs-Members.php'); Chris@76: if (isReservedName($username, $memID, false)) Chris@76: fatal_error('(' . htmlspecialchars($username) . ') ' . $txt['name_in_use'], false); Chris@76: Chris@76: return null; Chris@76: } Chris@76: Chris@76: // This function simply checks whether a password meets the current forum rules. Chris@76: function validatePassword($password, $username, $restrict_in = array()) Chris@76: { Chris@76: global $modSettings, $smcFunc; Chris@76: Chris@76: // Perform basic requirements first. Chris@76: if ($smcFunc['strlen']($password) < (empty($modSettings['password_strength']) ? 4 : 8)) Chris@76: return 'short'; Chris@76: Chris@76: // Is this enough? Chris@76: if (empty($modSettings['password_strength'])) Chris@76: return null; Chris@76: Chris@76: // Otherwise, perform the medium strength test - checking if password appears in the restricted string. Chris@76: if (preg_match('~\b' . preg_quote($password, '~') . '\b~', implode(' ', $restrict_in)) != 0) Chris@76: return 'restricted_words'; Chris@76: elseif ($smcFunc['strpos']($password, $username) !== false) Chris@76: return 'restricted_words'; Chris@76: Chris@76: // !!! If pspell is available, use it on the word, and return restricted_words if it doesn't give "bad spelling"? Chris@76: Chris@76: // If just medium, we're done. Chris@76: if ($modSettings['password_strength'] == 1) Chris@76: return null; Chris@76: Chris@76: // Otherwise, hard test next, check for numbers and letters, uppercase too. Chris@76: $good = preg_match('~(\D\d|\d\D)~', $password) != 0; Chris@76: $good &= $smcFunc['strtolower']($password) != $password; Chris@76: Chris@76: return $good ? null : 'chars'; Chris@76: } Chris@76: Chris@76: // Quickly find out what this user can and cannot do. Chris@76: function rebuildModCache() Chris@76: { Chris@76: global $user_info, $smcFunc; Chris@76: Chris@76: // What groups can they moderate? Chris@76: $group_query = allowedTo('manage_membergroups') ? '1=1' : '0=1'; Chris@76: Chris@76: if ($group_query == '0=1') Chris@76: { Chris@76: $request = $smcFunc['db_query']('', ' Chris@76: SELECT id_group Chris@76: FROM {db_prefix}group_moderators Chris@76: WHERE id_member = {int:current_member}', Chris@76: array( Chris@76: 'current_member' => $user_info['id'], Chris@76: ) Chris@76: ); Chris@76: $groups = array(); Chris@76: while ($row = $smcFunc['db_fetch_assoc']($request)) Chris@76: $groups[] = $row['id_group']; Chris@76: $smcFunc['db_free_result']($request); Chris@76: Chris@76: if (empty($groups)) Chris@76: $group_query = '0=1'; Chris@76: else Chris@76: $group_query = 'id_group IN (' . implode(',', $groups) . ')'; Chris@76: } Chris@76: Chris@76: // Then, same again, just the boards this time! Chris@76: $board_query = allowedTo('moderate_forum') ? '1=1' : '0=1'; Chris@76: Chris@76: if ($board_query == '0=1') Chris@76: { Chris@76: $boards = boardsAllowedTo('moderate_board', true); Chris@76: Chris@76: if (empty($boards)) Chris@76: $board_query = '0=1'; Chris@76: else Chris@76: $board_query = 'id_board IN (' . implode(',', $boards) . ')'; Chris@76: } Chris@76: Chris@76: // What boards are they the moderator of? Chris@76: $boards_mod = array(); Chris@76: if (!$user_info['is_guest']) Chris@76: { Chris@76: $request = $smcFunc['db_query']('', ' Chris@76: SELECT id_board Chris@76: FROM {db_prefix}moderators Chris@76: WHERE id_member = {int:current_member}', Chris@76: array( Chris@76: 'current_member' => $user_info['id'], Chris@76: ) Chris@76: ); Chris@76: while ($row = $smcFunc['db_fetch_assoc']($request)) Chris@76: $boards_mod[] = $row['id_board']; Chris@76: $smcFunc['db_free_result']($request); Chris@76: } Chris@76: Chris@76: $mod_query = empty($boards_mod) ? '0=1' : 'b.id_board IN (' . implode(',', $boards_mod) . ')'; Chris@76: Chris@76: $_SESSION['mc'] = array( Chris@76: 'time' => time(), Chris@76: // This looks a bit funny but protects against the login redirect. Chris@76: 'id' => $user_info['id'] && $user_info['name'] ? $user_info['id'] : 0, Chris@76: // If you change the format of 'gq' and/or 'bq' make sure to adjust 'can_mod' in Load.php. Chris@76: 'gq' => $group_query, Chris@76: 'bq' => $board_query, Chris@76: 'ap' => boardsAllowedTo('approve_posts'), Chris@76: 'mb' => $boards_mod, Chris@76: 'mq' => $mod_query, Chris@76: ); Chris@76: Chris@76: $user_info['mod_cache'] = $_SESSION['mc']; Chris@76: } Chris@76: Chris@76: ?>