初学乍练
- 贡献
- 0 点
- 金币
- 6 个
- 产品版本
- X3.4
|
楼主 |
发表于 2025-10-5 16:46:48
|
查看全部
经过对页面分析,应该是uc_client和uc_server下model的user模块中关于用户名判定check_username的代码有点兼容问题。
源代码如下:
- function check_username($username) {
- $charset = strtolower(UC_CHARSET);
- if ($charset === 'utf-8') {
- $guestexp = '\xE3\x80\x80|\xE6\xB8\xB8\xE5\xAE\xA2|\xE9\x81\x8A\xE5\xAE\xA2';
- } elseif ($charset === 'gbk') {
- $guestexp = '\xA1\xA1|\xD3\xCE\xBF\xCD';
- } elseif ($charset === 'big5') {
- $guestexp = '\xA1\x40|\xB9\x43\xAB\xC8';
- } else {
- return FALSE;
- }
- $guestexp .= '|^Guest';
- $len = $this->dstrlen($username);
- if($len > 15 || $len < 3 || preg_match("/\s+|^c:\\con\\con|[%,\*"\s\<\>\&\(\)']|$guestexp/is", $username)) {
- return FALSE;
- } else {
- return TRUE;
- }
- }
复制代码 应该是对游客(简写繁写)、guest、以及特殊字符进行判断,看是否有敏感的。既然代码兼容问题,考虑utf8一个汉字占3个字符,给做了修改
- function check_username($username) {
- // 1. 长度检查
- $len = $this->dstrlen($username);
- if($len > 21 || $len < 3) {
- return FALSE; // 长度不符合要求
- }
-
- // 2. 游客关键词检查(直接字符串匹配,更可靠)
- $charset = strtolower(UC_CHARSET);
- $isGuest = false;
-
- // 检查简繁体"游客"
- if (strpos($username, '游客') !== false || strpos($username, '遊客') !== false) {
- $isGuest = true;
- }
-
- // 检查全角空格(不同编码)
- if ($charset === 'utf-8' && strpos($username, ' ') !== false) { // UTF-8全角空格
- $isGuest = true;
- } elseif ($charset === 'gbk' && strpos($username, chr(0xA1).chr(0xA1)) !== false) { // GBK全角空格
- $isGuest = true;
- } elseif ($charset === 'big5' && strpos($username, chr(0xA1).chr(0x40)) !== false) { // Big5全角空格
- $isGuest = true;
- }
-
- // 检查Guest开头(不区分大小写)
- if (stripos($username, 'Guest') === 0) {
- $isGuest = true;
- }
-
- if ($isGuest) {
- return FALSE; // 包含游客相关内容
- }
-
- // 3. 特殊字符检查
- $specialChars = ['%', ',', '*', '"', '<', '>', '&', '(', ')', "'", ' ', "\t", "\r", "\n"];
- foreach ($specialChars as $char) {
- if (strpos($username, $char) !== false) {
- return FALSE; // 包含特殊字符
- }
- }
-
- // 4. 检查系统特殊名称
- if (strtolower($username) === 'c:\\\\con\\\\con') {
- return FALSE;
- }
-
- // 所有检查通过
- return TRUE;
- }
复制代码 测试通过。
当然,因为对长度进行了扩充,所以数据库中member相应的两个表中,要对username的字段长度将15变成21
|
|