使用uc_authcode 获取论坛当前登录用户信息
来源:互联网 发布:苹果电脑装什么软件 编辑:程序博客网 时间:2024/04/28 17:39
目的:使用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;
?>
- 使用uc_authcode 获取论坛当前登录用户信息
- Silverlight获取SharePoint当前登录用户信息
- spring boot +security获取当前登录用户信息
- 解决 CAS + Spring Security整合 无法获取当前登录用户信息
- 微博 JS SDK WB.login 获取当前登录用户信息
- Shiro(3) controller中获取当前登录用户信息
- sharepoint获取当前用户信息
- wordpress 获取当前用户信息
- liferay 获取登录用户信息
- androidQQ登录获取用户信息
- spring security 获取当前用户信息
- spring security 获取当前用户信息
- spring security 获取当前用户信息
- Linux获取当前用户信息函数
- google登录 java获取用户信息
- 微信小程序登录获取用户信息
- qt中获取当前登录的用户信息类的简单实现
- Linux如何查看系统当前登录用户信息
- 正则表达式30分钟入门教程(very good)
- 《Visual C++2010开发权威指南》版权输出台湾香港新加坡---大陆C++超越并引领台湾
- Combination Sum II
- jsp中js中submit失效
- 单向链表排序-归并排序
- 使用uc_authcode 获取论坛当前登录用户信息
- Set里的元素是不能重复的,那么用什么方法来区分重复与否呢? 是用==还是equals()? 它们有何区别?(例解)
- Java程序员从笨鸟到菜鸟之(二十一)java过滤器和监听器详解
- 周末讲座
- 移动开发:Ubunut 10.04 upgrade git
- Java程序员从笨鸟到菜鸟之(二十三)常见乱码解决以及javaBean基础知识
- 基于Visual C++2010与windows SDK fo windows7开发Windows 7的多点触摸特性应用程序(2)--手势识别应用
- 【leetcode】Letter Combinations of a Phone Number
- qsort函数 C语言快速排序函数