discuz论坛用户密码加密原理

一般我们的加密都是采用md5加密方式:md5(变量)。但是昨天需要整合discuz的论坛,看

他的加密方式也像是md5,但是简单的123加密后竟然解密不出来。后来在网上查了一下,

发现他不只是简单的md5加密,而是“md5+随机”。当然这样更安全了。

    网站安全了,程序自然也就复杂了...

    discuz的加密方式:md5(md5($password).$salt),$salt是一个6位随机数。

    注册的时候,把用户的密码用md5(md5($password).$salt)加密,$salt是一个6位随

机数字,下面是我的一个获取6位随机数的一个方法:

    function randstr($len=6) {

    $chars='abcdefghijklmnopqrstuvwxyz0123456789';

//characters to build the password from

    mt_srand((double)microtime()*1000000*getmypid());

// seedthe random number generater (must be done)

    $password='';

    while(strlen($password)<$len)

        $password.=substr($chars,(mt_rand()%strlen($chars)),1);

    return $password;

}

    $salt=randstr();把randstr()赋值给$salt,然后用md5(md5(会员提交的密

码).$salt)加密就可以了,但是千万不要忘了把$salt入库哦(uc_members表)。

    登陆的时候根据用户名把$salt取出来,用md5(md5(会员提交的密码).$salt)匹配密

码,如果一样就登陆成功了

猜你喜欢

转载自blog.csdn.net/czh0423/article/details/53199153
今日推荐