吾知网

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 5752|回复: 0
打印 上一主题 下一主题

使用uc_authcode 获取论坛当前登录用户信息

[复制链接]
跳转到指定楼层
楼主
发表于 2015-10-23 09:08:38 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

目的:使用uc_authcode 获取论坛当前登录用户信息

曲折:看了Discuz官方的ucenter二次开发手册,其中的Example如下:

if(!empty($_COOKIE['Example_auth'])) {
    list($Example_uid, $Example_username) = explode("\t", uc_authcode($_COOKIE['Example_auth'], 'DECODE'));
}

尝试使用uc_authcode 去解密论坛的auth时,解密结果一直为空,搜索了下资料,提示UC_KEY 与加密时的密钥不一致

于是将Discuz在Ucenter中的key 附到了参数后,  uc_authcode($_COOKIE['Example_auth'], 'DECODE','62cf0b3c3e6a4c9468e7216839721d8e')

思索了一下,决定去看下Discuz的登录逻辑,看到synlogin() 方法时,我全局搜索了一下,找到了/api/uc.php 文件,其中的

dsetcookie('auth', authcode("$member[password]\t$member[uid]", 'ENCODE'), $cookietime);

正是authcookie的内容,原来在discuz内部,并没有使用uc_authcode,而是使用了authcode,方法位于source/function/function_core.php

中,其加密key为 getglobal('authkey'),而function getglobal $_G['authkey'] 的值 在 source/class/class_core.php中被定义为

$this->var['authkey'] = md5($this->var['config']['security']['authkey'].$this->var['cookie']['saltkey']);

关键的几个信息就都找到了,解密的逻辑步骤如下:

authinfo.php (存放至根目录下)

------------------------------------

<?php
/*
*author:织梦的鱼
*time:2011.10.16
  *title:discuz x2 当前用户登录信息解密
*/
echo "<pre>";
if (!defined('APPROOT')) {
    define('APPROOT', dirname(__FILE__) . DIRECTORY_SEPARATOR);
}
if(!require_once(APPROOT . 'config' . DIRECTORY_SEPARATOR . 'config_global.php')){
    exit("该文件应存放于根目录下!");
}
include APPROOT . 'config' . DIRECTORY_SEPARATOR . 'config_ucenter.php';
include APPROOT . 'uc_client' . DIRECTORY_SEPARATOR . 'client.php';

if(substr($_config['cookie']['cookiepath'], 0, 1) != '/') {
            $_config['cookie']['cookiepath']= '/' . $_config['cookie']['cookiepath'];
}
$cookiepre =  $_config['cookie']['cookiepre'] . substr(md5($_config['cookie']['cookiepath'] . '|' .  $_config['cookie']['cookiedomain']), 0, 4) . '_';//COOKIE前缀

$auth = $cookiepre.'auth';//存储用户信息的COOKIE名
$saltkey = $_COOKIE[ $cookiepre . 'saltkey'];//解密auth用到的key

//$discuz_auth_key = md5($_config['security']['authkey'] . $_SERVER['HTTP_USER_AGENT']);//x1.5的密钥
$discuz_auth_key = md5($_config['security']['authkey'] . $saltkey);//x2的密钥
$auth_value = uc_authcode($_COOKIE[$auth],'DECODE',$discuz_auth_key);

//var_dump($_COOKIE);
//echo '<hr>';
echo "auth_cookie_value: " . $_COOKIE[$auth] . '<br>';

list($pwd,$uid ) = explode("\t", $auth_value);
echo "当前用户登录信息<br>";
echo 'UID:' . $uid." | 密码(md5):" . $pwd;
?>


您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|吾知网 ( 粤ICP备13013563号-1 )

GMT+8, 2024-4-28 23:12 , Processed in 1.093750 second(s), 10 queries , Memcache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表