mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 06:08:52 +00:00
banned usernames are now cached and normalized
git-svn-id: file:///svn/phpbb/trunk@6571 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
parent
90b16076d3
commit
b0217ddc11
3 changed files with 37 additions and 10 deletions
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue