{"id":352,"date":"2014-01-22T22:32:38","date_gmt":"2014-01-22T14:32:38","guid":{"rendered":"http:\/\/www.zyuns.com\/?p=352"},"modified":"2015-02-15T20:46:33","modified_gmt":"2015-02-15T12:46:33","slug":"shi-yong-uc-authcode-huo-qu-lun-tan-dang-qian-deng-lu-yong-hu-xin-xi","status":"publish","type":"post","link":"https:\/\/www.siediyer.cn\/?p=352","title":{"rendered":"\u4f7f\u7528uc_authcode \u83b7\u53d6\u8bba\u575b\u5f53\u524d\u767b\u5f55\u7528\u6237\u4fe1\u606f"},"content":{"rendered":"<div id=\"content\">\n<p>\u76ee\u7684\uff1a\u4f7f\u7528uc_authcode \u83b7\u53d6\u8bba\u575b\u5f53\u524d\u767b\u5f55\u7528\u6237\u4fe1\u606f<\/p>\n<p>\u66f2\u6298\uff1a\u770b\u4e86Discuz\u5b98\u65b9\u7684ucenter\u4e8c\u6b21\u5f00\u53d1\u624b\u518c\uff0c\u5176\u4e2d\u7684Example\u5982\u4e0b\uff1a<\/p>\n<p>if(!empty($_COOKIE[&#8216;Example_auth&#8217;])) {<br \/>\nlist($Example_uid, $Example_username) = explode(&#8220;t&#8221;, uc_authcode($_COOKIE[&#8216;Example_auth&#8217;], &#8216;DECODE&#8217;));<br \/>\n}<\/p>\n<p>\u5c1d\u8bd5\u4f7f\u7528uc_authcode \u53bb\u89e3\u5bc6\u8bba\u575b\u7684auth\u65f6\uff0c\u89e3\u5bc6\u7ed3\u679c\u4e00\u76f4\u4e3a\u7a7a\uff0c\u641c\u7d22\u4e86\u4e0b\u8d44\u6599\uff0c\u63d0\u793aUC_KEY \u4e0e\u52a0\u5bc6\u65f6\u7684\u5bc6\u94a5\u4e0d\u4e00\u81f4<\/p>\n<p>\u4e8e\u662f\u5c06Discuz\u5728Ucenter\u4e2d\u7684key \u9644\u5230\u4e86\u53c2\u6570\u540e\uff0c\u00a0 uc_authcode($_COOKIE[&#8216;Example_auth&#8217;], &#8216;DECODE&#8217;,&#8217;62cf0b3c3e6a4c9468e7216839721d8e&#8217;)<\/p>\n<p>\u601d\u7d22\u4e86\u4e00\u4e0b\uff0c\u51b3\u5b9a\u53bb\u770b\u4e0bDiscuz\u7684\u767b\u5f55\u903b\u8f91\uff0c\u770b\u5230synlogin() \u65b9\u6cd5\u65f6\uff0c\u6211\u5168\u5c40\u641c\u7d22\u4e86\u4e00\u4e0b\uff0c\u627e\u5230\u4e86\/api\/uc.php \u6587\u4ef6\uff0c\u5176\u4e2d\u7684<\/p>\n<p>dsetcookie(&#8216;auth&#8217;, authcode(&#8220;$member[password]t$member[uid]&#8221;, &#8216;ENCODE&#8217;), $cookietime);<\/p>\n<p>\u6b63\u662fauthcookie\u7684\u5185\u5bb9\uff0c\u539f\u6765\u5728discuz\u5185\u90e8\uff0c\u5e76\u6ca1\u6709\u4f7f\u7528uc_authcode\uff0c\u800c\u662f\u4f7f\u7528\u4e86authcode\uff0c\u65b9\u6cd5\u4f4d\u4e8esource\/function\/function_core.php<\/p>\n<p>\u4e2d\uff0c\u5176\u52a0\u5bc6key\u4e3a getglobal(&#8216;authkey&#8217;)\uff0c\u800cfunction getglobal $_G[&#8216;authkey&#8217;] \u7684\u503c \u5728 source\/class\/class_core.php\u4e2d\u88ab\u5b9a\u4e49\u4e3a<\/p>\n<p>$this-&gt;var[&#8216;authkey&#8217;] = md5($this-&gt;var[&#8216;config&#8217;][&#8216;security&#8217;][&#8216;authkey&#8217;].$this-&gt;var[&#8216;cookie&#8217;][&#8216;saltkey&#8217;]);<\/p>\n<p>\u5173\u952e\u7684\u51e0\u4e2a\u4fe1\u606f\u5c31\u90fd\u627e\u5230\u4e86\uff0c\u89e3\u5bc6\u7684\u903b\u8f91\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n<p>authinfo.php (\u5b58\u653e\u81f3\u6839\u76ee\u5f55\u4e0b)<\/p>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<\/p>\n<pre class=\"wrap:true lang:default decode:true \">&lt;?php\necho \"&lt;pre&gt;\";\nif (!defined('APPROOT')) {\n    define('APPROOT', dirname(__FILE__) . DIRECTORY_SEPARATOR);\n}\nif(!require_once(APPROOT . 'config' . DIRECTORY_SEPARATOR . 'config_global.php')){\n    exit(\"\u8be5\u6587\u4ef6\u5e94\u5b58\u653e\u4e8e\u6839\u76ee\u5f55\u4e0b\uff01\");\n}\ninclude APPROOT . 'config' . DIRECTORY_SEPARATOR . 'config_ucenter.php';\ninclude APPROOT . 'uc_client' . DIRECTORY_SEPARATOR . 'client.php';\n\nif(substr($_config['cookie']['cookiepath'], 0, 1) != '\/') {\n            $_config['cookie']['cookiepath']= '\/' . $_config['cookie']['cookiepath'];\n}\n$cookiepre =  $_config['cookie']['cookiepre'] . substr(md5($_config['cookie']['cookiepath'] . '|' .  $_config['cookie']['cookiedomain']), 0, 4) . '_';\/\/COOKIE\u524d\u7f00\n\n$auth = $cookiepre.'auth';\/\/\u5b58\u50a8\u7528\u6237\u4fe1\u606f\u7684COOKIE\u540d\n$saltkey = $_COOKIE[ $cookiepre . 'saltkey'];\/\/\u89e3\u5bc6auth\u7528\u5230\u7684key\n\n\/\/$discuz_auth_key = md5($_config['security']['authkey'] . $_SERVER['HTTP_USER_AGENT']);\/\/x1.5\u7684\u5bc6\u94a5\n$discuz_auth_key = md5($_config['security']['authkey'] . $saltkey);\/\/x2\u7684\u5bc6\u94a5\n$auth_value = uc_authcode($_COOKIE[$auth],'DECODE',$discuz_auth_key);\n\n\/\/var_dump($_COOKIE);\n\/\/echo '&lt;hr&gt;';\necho \"auth_cookie_value: \" . $_COOKIE[$auth] . '&lt;br&gt;';\n\nlist($pwd,$uid ) = explode(\"t\", $auth_value);\necho \"\u5f53\u524d\u7528\u6237\u767b\u5f55\u4fe1\u606f&lt;br&gt;\";\necho 'UID:' . $uid.\" | \u5bc6\u7801(md5):\" . $pwd;\n?&gt;<\/pre>\n<p>&nbsp;<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u76ee\u7684\uff1a\u4f7f\u7528uc_authcode \u83b7\u53d6\u8bba\u575b\u5f53\u524d\u767b\u5f55\u7528\u6237\u4fe1\u606f \u66f2\u6298\uff1a\u770b\u4e86Discuz\u5b98\u65b9\u7684ucenter\u4e8c\u6b21\u5f00\u53d1 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-352","post","type-post","status-publish","format-standard","hentry","category-php"],"_links":{"self":[{"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/posts\/352","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=352"}],"version-history":[{"count":1,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/posts\/352\/revisions"}],"predecessor-version":[{"id":419,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/posts\/352\/revisions\/419"}],"wp:attachment":[{"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=352"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=352"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=352"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}