最新消息:备用域名:https://yeeach.me

Discuz BBS及SNS用户密码加密算法

技术 admin 5896浏览 3评论

    在做项目时候需要集成discuz bbs、ucenter、ucenter home各个系统,这就要求自己的系统在进行用户注册时候同步在bbs、sns中增加对应的用户信息,由于discuz的各系统密码都为非明文串,因此要做到Discuz的用户帐户体系与业务系统同步,必然面临Discuz 用户密码加密算法问题。同时与同时由于有近百万的老的用户数据需要能够导入到bbs、sns的数据库中,因此方案应当支持批量导入操作。

1、可选方案

  • 程序通过ajax方式或httpclient模拟调用discuz ucenter home及bbs的注册url地址,提交接口所需要的各种参数完成注册操作

    此种方案中最为关键的是需要处理formhash问题,其他参数相对容易。

    在单个用户注册时候可以通过ajax方式或httpclient调用sns及bbs的注册接口自动完成注册。但在需要导入将近百万的老的用户数据时候,采用url接口调用方式性能太差,需要能够批量导入用户注册。    

  • 绕过web前端,从后端程序直接把用户注册数据插入数据库表中

    采用此种方案相对灵活,不用再受web前端的各种逻辑限制,同时对于大数据量导入也较好处理,因此采用此种方案。   

 

2、Discuz BBS及SNS密码加密算法

    Discuz SNS及BBS的密码采用非明文方式,加密算法如下(采用mysql函数方式描述):

        md5(concat(md5(‘password’),salt))

    其中salt为各用户在uc_members表中salt字段存放的随机串,实际上就是md5算法中的salt随机串,在批量导入时候,为方便起见,可以采用统一的字符串,我们测试暂且采用123456

    算法描述在ucenter/model/user.php中:

function check_login($username, $password, &$user) {
        $user = $this->get_user_by_username($username);
        if(empty($user['username'])) {
                return -1;
        } elseif($user['password'] != md5(md5($password).$user['salt'])) {
                return -2;
        }
        return $user['uid'];
}

function add_user($username, $password, $email, $uid = 0) {
        $salt = substr(uniqid(rand()), -6);
        $password = md5(md5($password).$salt);
        $sqladd = $uid ? 'uid=\''.intval($uid).'\',' : '';
        //$appid = $this->base->app[appid];
        $this->db->query("INSERT INTO ".UC_DBTABLEPRE."members SET $sqladd username='$username', password='$password', email='$email', regip='".$this->base->onlineip."', regdate='".$this->base->time."', salt='$salt'");
        $uid = $this->db->insert_id();
        $this->db->query("INSERT INTO ".UC_DBTABLEPRE."memberfields SET uid='$uid'");
        return $uid;
} 

3、插入用户数据方案

    insert into uc_members (uid,username,password,salt) values(id,‘username’, md5(concat(md5(‘password’),’123456′)),’123456’);

    insert into cdb_members (uid,username,password, groupid) values(id,‘username’, md5(concat(md5(‘password’),’123456′)),12);

    insert into cdb_memberfields(uid,nickname) values(id,’username’);

其中:

    id为max(uid)+10,uid本身在bbs、sns数据库中是自增的,但为保证3个表数据uid的同步,因此由程序指定uid,而不是自增方式。

    123456为salt值

    例如:

    insert into uc_members (uid,username,password,salt) values(203,’test5′, md5(concat(md5(‘test5′),’123456′)),’123456’);

    insert into cdb_members (uid,username,password, groupid) values(203,’test5′, md5(concat(md5(‘test5′),’123456’)),12);

    insert into cdb_memberfields(uid,nickname) values(203,’test5′);

   采用此种方案简单测试了一下,应该能够自动完成用户在BBS、Ucenter home中的自动登录,而且登录bbs时候不需要用户进行激活操作。先凑合用用,有空再完善相关功能。

4、表结构

  • uc_members表结构:

CREATE TABLE `uc_members` (

  `uid` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,

  `username` char(15) NOT NULL DEFAULT ”,

  `password` char(32) NOT NULL DEFAULT ”,

  `email` char(32) NOT NULL DEFAULT ”,

  `myid` char(30) NOT NULL DEFAULT ”,

  `myidkey` char(16) NOT NULL DEFAULT ”,

  `regip` char(15) NOT NULL DEFAULT ”,

  `regdate` int(10) unsigned NOT NULL DEFAULT ‘0’,

  `lastloginip` int(10) NOT NULL DEFAULT ‘0’,

  `lastlogintime` int(10) unsigned NOT NULL DEFAULT ‘0’,

  `salt` char(6) NOT NULL,

  PRIMARY KEY (`uid`),

  UNIQUE KEY `username` (`username`)

) ENGINE=MyISAM AUTO_INCREMENT=194 DEFAULT CHARSET=utf8

  • cdb_members表结构

CREATE TABLE `cdb_members` (

  `uid` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,

  `username` char(15) NOT NULL DEFAULT ”,

  `password` char(32) NOT NULL DEFAULT ”,

  `secques` char(8) NOT NULL DEFAULT ”,

  `gender` tinyint(1) NOT NULL DEFAULT ‘0’,

  `adminid` tinyint(1) NOT NULL DEFAULT ‘0’,

  `groupid` smallint(6) unsigned NOT NULL DEFAULT ‘0’,

  `groupexpiry` int(10) unsigned NOT NULL DEFAULT ‘0’,

  `extgroupids` char(20) NOT NULL DEFAULT ”,

  `regip` char(15) NOT NULL DEFAULT ”,

  `regdate` int(10) unsigned NOT NULL DEFAULT ‘0’,

  `lastip` char(15) NOT NULL DEFAULT ”,

  `lastvisit` int(10) unsigned NOT NULL DEFAULT ‘0’,

  `lastactivity` int(10) unsigned NOT NULL DEFAULT ‘0’,

  `lastpost` int(10) unsigned NOT NULL DEFAULT ‘0’,

  `posts` mediumint(8) unsigned NOT NULL DEFAULT ‘0’,

  `digestposts` smallint(6) unsigned NOT NULL DEFAULT ‘0’,

  `oltime` smallint(6) unsigned NOT NULL DEFAULT ‘0’,

  `pageviews` mediumint(8) unsigned NOT NULL DEFAULT ‘0’,

  `credits` int(10) NOT NULL DEFAULT ‘0’,

  `extcredits1` int(10) NOT NULL DEFAULT ‘0’,

  `extcredits2` int(10) NOT NULL DEFAULT ‘0’,

  `extcredits3` int(10) NOT NULL DEFAULT ‘0’,

  `extcredits4` int(10) NOT NULL DEFAULT ‘0’,

  `extcredits5` int(10) NOT NULL DEFAULT ‘0’,

  `extcredits6` int(10) NOT NULL DEFAULT ‘0’,

  `extcredits7` int(10) NOT NULL DEFAULT ‘0’,

  `extcredits8` int(10) NOT NULL DEFAULT ‘0’,

  `email` char(40) NOT NULL DEFAULT ”,

  `bday` date NOT NULL DEFAULT ‘0000-00-00’,

  `sigstatus` tinyint(1) NOT NULL DEFAULT ‘0’,

  `tpp` tinyint(3) unsigned NOT NULL DEFAULT ‘0’,

  `ppp` tinyint(3) unsigned NOT NULL DEFAULT ‘0’,

  `styleid` smallint(6) unsigned NOT NULL DEFAULT ‘0’,

  `dateformat` tinyint(1) NOT NULL DEFAULT ‘0’,

  `timeformat` tinyint(1) NOT NULL DEFAULT ‘0’,

  `pmsound` tinyint(1) NOT NULL DEFAULT ‘0’,

  `showemail` tinyint(1) NOT NULL DEFAULT ‘0’,

  `newsletter` tinyint(1) NOT NULL DEFAULT ‘0’,

  `invisible` tinyint(1) NOT NULL DEFAULT ‘0’,

  `timeoffset` char(4) NOT NULL DEFAULT ”,

  `newpm` tinyint(1) NOT NULL DEFAULT ‘0’,

  `accessmasks` tinyint(1) NOT NULL DEFAULT ‘0’,

  `editormode` tinyint(1) unsigned NOT NULL DEFAULT ‘2’,

  `customshow` tinyint(1) unsigned NOT NULL DEFAULT ’26’,

  `xspacestatus` tinyint(1) NOT NULL DEFAULT ‘0’,

  `customaddfeed` tinyint(1) NOT NULL DEFAULT ‘0’,

  PRIMARY KEY (`uid`),

  UNIQUE KEY `username` (`username`),

  KEY `email` (`email`),

  KEY `groupid` (`groupid`)

) ENGINE=MyISAM AUTO_INCREMENT=194 DEFAULT CHARSET=utf8

  • cdb_memberfields表结构

CREATE TABLE `cdb_memberfields` (

  `uid` mediumint(8) unsigned NOT NULL DEFAULT ‘0’,

  `nickname` varchar(30) NOT NULL DEFAULT ”,

  `site` varchar(75) NOT NULL DEFAULT ”,

  `alipay` varchar(50) NOT NULL DEFAULT ”,

  `icq` varchar(12) NOT NULL DEFAULT ”,

  `qq` varchar(12) NOT NULL DEFAULT ”,

  `yahoo` varchar(40) NOT NULL DEFAULT ”,

  `msn` varchar(40) NOT NULL DEFAULT ”,

  `taobao` varchar(40) NOT NULL DEFAULT ”,

  `location` varchar(30) NOT NULL DEFAULT ”,

  `customstatus` varchar(30) NOT NULL DEFAULT ”,

  `medals` text NOT NULL,

  `avatar` varchar(255) NOT NULL DEFAULT ”,

  `avatarwidth` tinyint(3) unsigned NOT NULL DEFAULT ‘0’,

  `avatarheight` tinyint(3) unsigned NOT NULL DEFAULT ‘0’,

  `bio` text NOT NULL,

  `sightml` text NOT NULL,

  `ignorepm` text NOT NULL,

  `groupterms` text NOT NULL,

  `authstr` varchar(20) NOT NULL DEFAULT ”,

  `spacename` varchar(40) NOT NULL,

  `buyercredit` smallint(6) NOT NULL DEFAULT ‘0’,

  `sellercredit` smallint(6) NOT NULL DEFAULT ‘0’,

  PRIMARY KEY (`uid`)

) ENGINE=MyISAM DEFAULT CHARSET=utf8

5、关于discuz的formhash问题的备注

    从目前研究的结果来看,discuz bbs的formhash有两种:登录(注销)的formhash和发帖(回帖)的formhash

    获取discuz bbs的formhash的方案如下(ucenter home的有空再研究,应该与此类似):

     在登陆前,首先在未登录状态下访问bbs登录url地址:http://www.yeeach.com/bbs/logging.php?action=login以获取登录formhash,然后使用此formhash进行正常的登录操作。

    在发帖前,首先访问发帖url地址http://www.yeeach.com/bbs/post.php?action=newthread&fid=101以获取发帖formahsh,然后使用此formhash进行正常的发帖操作。

 

6、参考文档

    http://www.akii.org/discuz_md5_salt/

 

转载请注明:出家如初,成佛有余 » Discuz BBS及SNS用户密码加密算法

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

网友最新评论 (3)

  1. 非常感谢
    liyihai15年前 (2009-06-15)回复
  2. The fortuitous people at Capital rihanna naked FM’s Summertime Ball’ in London were understood a special treat model weekend: the ultra-talented Rihanna bump the put on to operate her worldwide hit ‘Rude Attendant’. Voucher exposed the performance underneath: independent rihanna naked fully naked flagrant images rihanna naked pussy rihanna naked sin up to date undisguised trendy in the buff photos rihanna in the nude ass rihanna nude egotastic rihanna bare pics rihanna nude photos uncensored rihanna nude pussy
    54SydneyBirdwell14年前 (2010-06-09)回复
  3. 不错,我用上了~!多谢老大分享
    Larry14年前 (2010-07-02)回复