|
經過對頁面分析,應該是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開頭(不區(qū)分大小寫)
- 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. 檢查系統(tǒng)特殊名稱
- if (strtolower($username) === 'c:\\\\con\\\\con') {
- return FALSE;
- }
-
- // 所有檢查通過
- return TRUE;
- }
復制代碼 測試通過。
當然,因為對長度進行了擴充,所以數據庫中member相應的兩個表中,要對username的字段長度將15變成21
|
|