五月综合缴情婷婷六月,色94色欧美sute亚洲线路二,日韩制服国产精品一区,色噜噜一区二区三区,香港三级午夜理伦三级三

您現(xiàn)在的位置: 365建站網(wǎng) > 365文章 > [原創(chuàng)]uchome登陸機(jī)制分析

[原創(chuàng)]uchome登陸機(jī)制分析

文章來源:365jz.com     點(diǎn)擊數(shù):1081    更新時(shí)間:2009-09-21 11:06   參與評(píng)論

嘿嘿,我的獨(dú)立博客對應(yīng)的地址:http://imzc.net/show-102-1.html


uchome_ROOT/為uchome的根目錄
第一步:
定位到uchome_ROOT/source/do_login.php,找到如下函數(shù):

PHP代碼
  1. //同步獲取用戶源  
  2. if(!$passport = getpassport($username$password)) {  
  3.     showmessage('login_failure_please_re_login''do.php?ac='.$_SCONFIG['login_action']);  
  4. }  

上示函數(shù)便是登陸的第一步處理函數(shù),再次定位:

uchome_ROOT/source/function_common.php,找到如下函數(shù):

 

PHP代碼
  1. //獲取用戶數(shù)據(jù)  
  2. function getpassport($username$password) {  
  3.     global $_SGLOBAL$_SC;  
  4.   
  5.     $passport = array();  
  6.     if(!@include_once S_ROOT.'./uc_client/client.php') {  
  7.         showmessage('system_error');  
  8.     }  
  9.   
  10.     $ucresult = uc_user_login($username$password);  
  11.     if($ucresult[0] > 0) {  
  12.         $passport['uid'] = $ucresult[0];  
  13.         $passport['username'] = $ucresult[1];  
  14.         $passport['email'] = $ucresult[3];  
  15.     }  
  16.     return $passport;  
  17. }  

至此,我們可以發(fā)現(xiàn)現(xiàn)在開始和uc_client相關(guān)函數(shù)關(guān)聯(lián)了.我們進(jìn)入uc_client文件夾,開始分析,定位至:uchome_ROOT/uc_client/client.php

 

 

PHP代碼
  1. /** 
  2.  * 用戶登陸檢查 
  3.  * 
  4.  * @param string $username  用戶名/uid 
  5.  * @param string $password  密碼 
  6.  * @param int $isuid        是否為uid 
  7.  * @param int $checkques    是否使用檢查安全問答 
  8.  * @param int $questionid   安全提問 
  9.  * @param string $answer    安全提問答案 
  10.  * @return array (uid/status, username, password, email) 
  11.     數(shù)組第一項(xiàng) 
  12.     1  : 成功 
  13.     -1 : 用戶不存在,或者被刪除 
  14.     -2 : 密碼錯(cuò) 
  15. */  
  16. function uc_user_login($username$password$isuid = 0, $checkques = 0, $questionid = ''$answer = '') {  
  17.     $isuid = intval($isuid);  
  18.     //define('UC_API_FUNC', UC_CONNECT == 'mysql' ? 'uc_api_mysql' : 'uc_api_post');  
  19.     $return = call_user_func(UC_API_FUNC, 'user''login'array('username'=>$username'password'=>$password'isuid'=>$isuid'checkques'=>$checkques'questionid'=>$questionid'answer'=>$answer));  
  20.     return UC_CONNECT == 'mysql' ? $return : uc_unserialize($return);  
  21. }  

因?yàn)槭莔ysql,故,UC_API_FUNC的值為uc_api_mysql,通過call_user_func()函數(shù),將參數(shù)傳給uc_api_mysql(),下面進(jìn)入最關(guān)鍵的函數(shù)了:

 

uchome_ROOT/uc_client/client.php => uc_api_mysql()

PHP代碼
  1. /** 
  2.  * MYSQL 方式取指定的模塊和動(dòng)作的數(shù)據(jù) 
  3.  * 
  4.  * @param string $model     請求的模塊 
  5.  * @param string $action    請求的動(dòng)作 
  6.  * @param string $args      參數(shù)(會(huì)加密的方式傳送) 
  7.  * @return mix 
  8.  */  
  9.   
  10. function uc_api_mysql($model$action$args=array()) {  
  11.     //$model = 'user',$action= 'login',  
  12.     //$args = Array ( [username] => test2 [password] => test [isuid] => 0 [checkques] => 0 [questionid] => [answer] => )   
  13.     global $uc_controls;  
  14.     if(empty($uc_controls[$model])) {  
  15.         //UC_ROOT uc_client/  
  16.         include_once UC_ROOT.'./lib/db.class.php';  
  17.         include_once UC_ROOT.'./model/base.php';  
  18.         include_once UC_ROOT."./control/$model.php";  
  19.         eval("\$uc_controls['$model'] = new {$model}control();");  
  20.         //uc_client/control/user.php,usercontrol()類(繼承至base基類)實(shí)例化  
  21.     }  
  22.     if($action{0} != '_') {  
  23.         $args = uc_addslashes($args, 1, TRUE);  
  24.         $action = 'on'.$action;//onlogin,usercontrol()中的方法,可以考慮改造此函數(shù)以實(shí)現(xiàn)預(yù)定功能  
  25.         $uc_controls[$model]->input = $args;//base.php,base基類的方法  
  26.         //return Array ( [0] => 3 [1] => test2 [2] => test [3] => test@12.com [4] => 0 )   
  27.           
  28.         return $uc_controls[$model]->$action($args);//返回預(yù)定數(shù)組,供調(diào)用函數(shù)分析  
  29.     } else {  
  30.         return '';  
  31.     }  
  32. }  
我們看看usercontrol類的onlogin()方法:

uchome_ROOT/uc_client/control/user.php

PHP代碼
  1. //note public 外部接口 登陸接口  
  2. function onlogin() {  
  3.     $this->init_input();  
  4.     $isuid = $this->input('isuid');  
  5.     $username = $this->input('username');  
  6.     $password = $this->input('password');  
  7.     $checkques = $this->input('checkques');  
  8.     $questionid = $this->input('questionid');  
  9.     $answer = $this->input('answer');  
  10.     if($isuid) {  
  11.         $user = $_ENV['user']->get_user_by_uid($username);  
  12.     } else {  
  13.         $user = $_ENV['user']->get_user_by_username($username);  
  14.     }  
  15.   //這部分即可改動(dòng)
  16.     $passwordmd5 = preg_match('/^\w{32}$/'$password) ? $password : md5($password);  
  17.     //note 用戶名不存在  
  18.     if(empty($user)) {  
  19.         $status = -1;  
  20.     } elseif($user['password'] != md5($passwordmd5.$user['salt'])) {  
  21.         $status = -2;  
  22.     } elseif($checkques && $user['secques'] != '' && $user['secques'] != $_ENV['user']->quescrypt($questionid$answer)) {  
  23.         $status = -3;  
  24.     } else {  
  25.         $status = $user['uid'];  
  26.     }  
  27.     $merge = $status != -1 && !$isuid && $_ENV['user']->check_mergeuser($username) ? 1 : 0;  
  28.     return array($status$user['username'], $password$user['email'], $merge);  
  29. }  
可以改成如下形式:

PHP代碼
  1. //note public 外部接口 登陸接  
  2.     function onlogin($type='myself') {  
  3.         $this->init_input();  
  4.         $isuid = $this->input('isuid');  
  5.         $username = $this->input('username');  
  6.         $password = $this->input('password');  
  7.         $checkques = $this->input('checkques');  
  8.         $questionid = $this->input('questionid');  
  9.         $answer = $this->input('answer');  
  10.         if($isuid) {  
  11.             $user = $_ENV['user']->get_user_by_uid($username);  
  12.         } else {  
  13.             $user = $_ENV['user']->get_user_by_username($username);  
  14.         }  
  15.   
  16.         $passwordmd5 = preg_match('/^\w{32}$/'$password) ? $password : md5($password);  
  17.   
  18.         $type='myself';  
  19.         if($type=='myself')  
  20.         {  
  21.             echo '$password:'.$password.'<br>';  
  22.             $testmd5 = md5('test');//假設(shè)數(shù)據(jù)庫中保持的所有的密碼為test  
  23. //          print_r($passwordmd5);  
  24. //          print_r($user);  
  25.             //note 用戶名不存在  
  26.               
  27.             if(emptyempty($user)) {  
  28.                 $status = -1;  
  29.             } elseif($user['password'] != $passwordmd5) {  
  30.                 $status = -2;  
  31.             } elseif($checkques && $user['secques'] != '' && $user['secques'] != $_ENV['user']->quescrypt($questionid$answer)) {  
  32.                 $status = -3;  
  33.             } else {  
  34.                 $status = $user['uid'];  
  35.             }  
  36. //          echo '<br>$statusz:'.$status.'<br>';  
  37. //          die();  
  38.         }else{  
  39.             if(emptyempty($user)) {  
  40.                 $status = -1;  
  41.             } elseif($user['password'] != md5($passwordmd5.$user['salt'])) {  
  42.                 $status = -2;  
  43.             } elseif($checkques && $user['secques'] != '' && $user['secques'] != $_ENV['user']->quescrypt($questionid$answer)) {  
  44.                 $status = -3;  
  45.             } else {  
  46.                 $status = $user['uid'];  
  47.             }  
  48.         }  
  49.         $merge = $status != -1 && !$isuid && $_ENV['user']->check_mergeuser($username) ? 1 : 0;  
  50.         return array($status$user['username'], $password$user['email'], $merge);  
  51.     }  

至此,我們可以更改uchome默認(rèn)的認(rèn)證方式了,如果這里更改了,以后相關(guān)的也需要作出更改,這個(gè)就留下大家自己去跟蹤調(diào)試了.

tips:

uchome_ROOT/uc_client/model/user.php下還有一個(gè)check_login(),這個(gè)函數(shù)暫時(shí)沒有找到調(diào)用的地方.

PHP代碼
  1. function check_login($username$password, &$user) {  
  2.     $user = $this->get_user_by_username($username); 
  3.     if(empty($user['username'])) {  
  4.         return -1;  
  5.     } elseif($user['password'] != md5(md5($password).$user['salt'])) {  
  6.         return -2;  
  7.     }  
  8.     return $user['uid'];  
  9. }  

eclipsePDT還是不錯(cuò)的,可以試試這個(gè)IDE.


 

 

且行且珍惜...

作者資料:
O(∩_∩)O川zc
我的主頁  個(gè)人資料
我的閃存  與我聯(lián)系

如對本文有疑問,請?zhí)峤坏浇涣髡搲瑥V大熱心網(wǎng)友會(huì)為你解答?。?點(diǎn)擊進(jìn)入論壇

發(fā)表評(píng)論 (1081人查看,0條評(píng)論)
請自覺遵守互聯(lián)網(wǎng)相關(guān)的政策法規(guī),嚴(yán)禁發(fā)布色情、暴力、反動(dòng)的言論。
昵稱:
最新評(píng)論
------分隔線----------------------------

其它欄目

· 建站教程
· 365學(xué)習(xí)

業(yè)務(wù)咨詢

· 技術(shù)支持
· 服務(wù)時(shí)間:9:00-18:00
365建站網(wǎng)二維碼

Powered by 365建站網(wǎng) RSS地圖 HTML地圖

copyright © 2013-2024 版權(quán)所有 鄂ICP備17013400號(hào)