diff --git a/phpBB/includes/acp/acp_disallow.php b/phpBB/includes/acp/acp_disallow.php index 41ca1ca276..adb7270332 100644 --- a/phpBB/includes/acp/acp_disallow.php +++ b/phpBB/includes/acp/acp_disallow.php @@ -43,6 +43,8 @@ class acp_disallow $sql = 'INSERT INTO ' . DISALLOW_TABLE . ' ' . $db->sql_build_array('INSERT', array('disallow_username' => $disallowed_user)); $db->sql_query($sql); + $cache->destroy('disallowed_usernames'); + $message = $user->lang['DISALLOW_SUCCESSFUL']; add_log('admin', 'LOG_DISALLOW_ADD', str_replace('%', '*', $disallowed_user)); @@ -61,6 +63,8 @@ class acp_disallow WHERE disallow_id = ' . $disallowed_id; $db->sql_query($sql); + $cache->destroy('disallowed_usernames'); + add_log('admin', 'LOG_DISALLOW_DELETE'); trigger_error($user->lang['DISALLOWED_DELETED'] . adm_back_link($this->u_action), E_USER_WARNING); diff --git a/phpBB/includes/cache.php b/phpBB/includes/cache.php index 8d6e17a8df..01dcf5b722 100644 --- a/phpBB/includes/cache.php +++ b/phpBB/includes/cache.php @@ -354,6 +354,29 @@ class cache extends acm return $parsed_items; } + + function obtain_disallowed_usernames(&$usernames) + { + if (($usernames = $this->get('disallowed_usernames')) === false) + { + global $db; + + $sql = 'SELECT disallow_username + FROM ' . DISALLOW_TABLE; + $result = $db->sql_query($sql); + + $usernames = array(); + while ($row = $db->sql_fetchrow($result)) + { + $usernames[] = utf8_clean_string(str_replace('%', '.*?', preg_quote($row['disallow_username'], '$#'))); + } + $db->sql_freeresult($result); + + $this->put('disallowed_usernames', $usernames); + } + + return true; + } } ?> \ No newline at end of file diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 56b92f850b..a1bdec1695 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -1120,9 +1120,11 @@ function validate_match($string, $optional = false, $match) */ function validate_username($username) { - global $config, $db, $user; + global $config, $db, $user, $cache; - if (utf8_clean_string($user->data['username']) == utf8_clean_string($username)) + $clean_username = utf8_clean_string($username); + + if (utf8_clean_string($user->data['username']) == $clean_username) { return false; } @@ -1134,7 +1136,7 @@ function validate_username($username) $sql = 'SELECT username FROM ' . USERS_TABLE . " - WHERE username_clean = '" . $db->sql_escape(utf8_clean_string($username)) . "'"; + WHERE username_clean = '" . $db->sql_escape($clean_username) . "'"; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); @@ -1156,19 +1158,17 @@ function validate_username($username) return 'USERNAME_TAKEN'; } - $sql = 'SELECT disallow_username - FROM ' . DISALLOW_TABLE; - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + $bad_usernames = array(); + $cache->obtain_disallowed_usernames($bad_usernames); + + foreach ($bad_usernames as $bad_username) { - if (preg_match('#^' . str_replace('%', '.*?', preg_quote($row['disallow_username'], '$#')) . '#i', $username)) + if (preg_match('#^' . $bad_username . '#', $clean_username)) { - $db->sql_freeresult($result); return 'USERNAME_DISALLOWED'; } } - $db->sql_freeresult($result); $sql = 'SELECT word FROM ' . WORDS_TABLE;