1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-06-05 05:55:15 +02:00
git-svn-id: file:///svn/phpbb/trunk@7374 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
David M 2007-04-19 20:59:52 +00:00
parent 897e0f952d
commit 1ca1021134
4 changed files with 95 additions and 7 deletions

View File

@ -679,13 +679,12 @@ class acp_board
{
global $user;
$user_char_ary = array('USERNAME_CHARS_ANY' => '.*', 'USERNAME_ALPHA_ONLY' => '[a-z]+', 'USERNAME_ALPHA_SPACERS' => '[-\]_+ [a-z]+', 'USERNAME_LETTER_NUM' => '\w+', 'USERNAME_LETTER_NUM_SPACERS' => '[-\]_+ [\w]+', 'USERNAME_ASCII' => '[\x01-\x7F]+');
$user_char_ary = array('USERNAME_CHARS_ANY', 'USERNAME_ALPHA_ONLY', 'USERNAME_ALPHA_SPACERS', 'USERNAME_LETTER_NUM', 'USERNAME_LETTER_NUM_SPACERS', 'USERNAME_ASCII');
$user_char_options = '';
foreach ($user_char_ary as $lang => $value)
foreach ($user_char_ary as $user_type)
{
$selected = ($selected_value == $value) ? ' selected="selected"' : '';
$user_char_options .= '<option value="' . $value . '"' . $selected . '>' . $user->lang[$lang] . '</option>';
$selected = ($selected_value == $user_type) ? ' selected="selected"' : '';
$user_char_options .= '<option value="' . $user_type . '"' . $selected . '>' . $user->lang[$user_type] . '</option>';
}
return $user_char_options;

View File

@ -1184,7 +1184,92 @@ function validate_username($username, $allowed_username = false)
return false;
}
if (!preg_match('#^' . str_replace('\\\\', '\\', $config['allow_name_chars']) . '$#ui', $username) || strpos($username, '&quot;') !== false || strpos($username, '"') !== false)
$mbstring = $pcre = false;
// generic UTF-8 character types supported?
if (version_compare(PHP_VERSION, '5.1.0', '>=') || (version_compare(PHP_VERSION, '5.0.0-dev', '<=') && version_compare(PHP_VERSION, '4.4.0', '>=')))
{
$pcre = true;
}
else if (function_exists('mb_ereg_match'))
{
mb_regex_encoding('UTF-8');
$mbstring = true;
}
switch ($config['allow_name_chars'])
{
case 'USERNAME_CHARS_ANY':
$pcre = true;
$regex = '.+';
break;
case 'USERNAME_ALPHA_ONLY':
$pcre = true;
$regex = '[A-Za-z]+';
break;
case 'USERNAME_ALPHA_SPACERS':
$pcre = true;
$regex = '[-\]_+ ]+';
break;
case 'USERNAME_LETTER_NUM':
if ($pcre)
{
$regex = '[\p{Lu}\p{Ll}\p{N}]+';
}
else if ($mbstring)
{
$regex = '[[:upper:][:lower:][:digit:]]+';
}
else
{
$pcre = true;
$regex = '[a-zA-Z0-9]+';
}
break;
case 'USERNAME_LETTER_NUM_SPACERS':
if ($pcre)
{
$regex = '[-\]_+ [\p{Lu}\p{Ll}\p{N}]+';
}
else if ($mbstring)
{
$regex = '[-\]_+ [[:upper:][:lower:][:digit:]]+';
}
else
{
$pcre = true;
$regex = '[-\]_+ [a-zA-Z0-9]+';
}
break;
case 'USERNAME_ASCII':
$pcre = true;
$regex = '[\x01-\x7F]+';
break;
}
if ($pcre)
{
if (!preg_match('#^' . $regex . '$#u', $username))
{
return 'INVALID_CHARS';
}
}
else if ($mbstring)
{
$matches = array();
mb_ereg_search_init('^' . $username . '$', $regex, $matches);
if (!mb_ereg_search())
{
return 'INVALID_CHARS';
}
}
if (strpos($username, '&quot;') !== false || strpos($username, '"') !== false)
{
return 'INVALID_CHARS';
}

View File

@ -1037,6 +1037,10 @@ if (version_compare($current_version, '3.0.b5', '<='))
$db->sql_query($sql);
}
$user_char_ary = array('.*' => 'USERNAME_CHARS_ANY', '[a-z]+' => 'USERNAME_ALPHA_ONLY', '[-\]_+ [a-z]+' => 'USERNAME_ALPHA_SPACERS', '\w+' => 'USERNAME_LETTER_NUM', '[-\]_+ [\w]+' => 'USERNAME_LETTER_NUM_SPACERS', '[\x01-\x7F]+' => 'USERNAME_ASCII');
set_config('allow_name_chars', $config['allow_name_chars']);
// sorting thang
if ($map_dbms === 'mysql_41')
{

View File

@ -18,7 +18,7 @@ INSERT INTO phpbb_config (config_name, config_value) VALUES ('allow_bookmarks',
INSERT INTO phpbb_config (config_name, config_value) VALUES ('allow_emailreuse', '0');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('allow_forum_notify', '1');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('allow_mass_pm', '1');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('allow_name_chars', '.*');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('allow_name_chars', 'USERNAME_CHARS_ANY');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('allow_namechange', '0');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('allow_nocensors', '0');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('allow_pm_attach', '0');