Home >Backend Development >PHP Tutorial >Discuz经典的用户信息加密算法

Discuz经典的用户信息加密算法

WBOY
WBOYOriginal
2016-06-20 13:01:331185browse

Discuz经典的用户信息加密算法

/**
 *用户信息加密解密函数
 *
 *待加密内容用/t分割
 *@return String 加密或解密字符串
 *@param String $string 待加密或解密字符串
 *@param String $operation 操作类型定义 DECODE=解密 ENDODE=加密
 *@param String $key 加密算子
 */
function authcode($string, $operation, $key = '') {
/**
 *获取密码算子,如未指定,采取系统默认算子
 *默认算子是论坛授权码和用户浏览器信息的md5散列值
 *$GLOBALS['discuz_auth_key']----全局变量
 *取值为:md5($_DCACHE['settings']['authkey'].$_SERVER['HTTP_USER_AGENT'])
 *$_DCACHE['settings']['authkey']是论坛安装时生成的15位随机字符串
 */
    $key = md5($key ? $key : $GLOBALS['discuz_auth_key']);
    $key_length = strlen($key);
/**
 *如果解密,先对密文解码
 *如果加密,将密码算子和待加密字符串进行md5运算后取前8位
 *并将这8位字符串和待加密字符串连接成新的待加密字符串
 */
    $string = $operation == 'DECODE' ? base64_decode($string) : substr(md5($string.$key), 0, 8).$string;
    $string_length = strlen($string);
    $rndkey = $box = array();
    $result = '';
  
/**
 *初始化加密变量,$rndkey和$box
 */
    for($i = 0; $i <p class="item-note"><br></p>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn