|
步骤一,所有原来默认的字段名uin改为uid
步骤二,大厅DLL源程序 db.cpp 中修改 OnUserLogin() 函数,参考内容如下:
- long OnUserLogin(LPCTSTR lpszUser, LPCTSTR lpszPasswd, LPCTSTR lpszIP, LPCTSTR lpszConnect)
- {
- long nUin = -1;//atol( lpszUser ); //转换为ID号
- CString strCmd;
- CDatabase db; CRecordset rs; rs.m_pDatabase = &db;
- try
- {
- //采用名字登录必须注册防止名字为“天云上人' or username='随便”
- //这里采用的是判断名字是否含有“ ”或“'”的办法
- int ndx = 0;
- while( lpszUser[ndx] )
- {
- if( lpszUser[ndx] == ' ' || lpszUser[ndx] == '\'' )
- {
- break;
- }
- ndx ++;
- }
- if( lpszUser[ndx] == 0 )
- { //没有发现含有非法字符,可以登录判断
- db.OpenEx( lpszConnect, CDatabase::noOdbcDialog );
- //验证玩家帐号
- strCmd.Format( "select %s from %s where %s='%s' and %s=md5('%s')",
- DB_FD_ID, DB_TB_AUTH, DB_FD_USERNAME, lpszUser, DB_FD_PASSWORD, lpszPasswd );
- rs.Open( AFX_DB_USE_DEFAULT_TYPE, strCmd);
- if( rs.IsEOF() )
- { //验证未通过, 返回-1
- nUin = -1;
- }
- else
- { //验证通过,则取ID号
- rs.GetFieldValue( DB_FD_ID, strCmd );
- nUin = atol( strCmd );
- }
- }
- else
- { //发现了非法字符,不让登录
- nUin = -1;
- }
- }
- catch(...)
- {
- nUin = -4;
- }
- rs.Close(); db.Close();
- return nUin;
- }
复制代码
步骤三、大厅DLL源程序 db.h 中修改表和字段定义,参考内容如下:
- //玩家基本信息表
- #define DB_TB_AUTH "cdb_members" //表名
- #define DB_FD_ID "uid" //ID字段名
- #define DB_FD_USERNAME "username" //玩家名称
- #define DB_FD_PASSWORD "password" //密码字段名
- //游戏设置信息表
复制代码
步骤四、修改完以上内容编译生成DLL即可使用Discuz! 2.0 数据库+名称+密码方式登录大厅。 |
|