socketio mysql_SocketIO + MySQL认证

我正在尝试通过socketIO在MySQL

DB上进行身份验证。我已经建立了连接,并且可以毫无问题地查询结果,但是由于某些原因,我无法将用户是否通过connection套接字验证。这个想法是我的应用拥有主持人和查看者。如果在未发送密码的情况下连接到该应用程序,则QueryString该应用程序将视为其查看者并接受连接。如果发送了密码,则会对照数据库进行检查并接受/拒绝连接。我希望将变量传递给,connection以便可以在我的应用程序事件中使用它。这是我到目前为止的内容,但显然data.query['ishost']并没有传递到应用程序中。

sio.configure(function() {

sio.set('authorization', function (data, accept) {

UserID = data.query['username'];

try {

UserID = UserID.toLowerCase();

} catch(err) {

return accept("No WebBot Specified. ("+err+")", false);

}

// if not sending a password, skip authorization and connect as a viewer

if (data.query['password'] === 'undefined')

{

return accept(null, true);

}

// if sending a password, attempt authorization and connect as a host

else

{

client.query(

'SELECT * FROM web_users WHERE username = "'+UserID+'" LIMIT 1',

function selectCb(err, results, fields) {

if (err) {

throw err;

}

// Found match, hash password and check against DB

if (results.length != 0)

{

// Passwords match, authenticate.

if (hex_md5(data.query['password']) == results[0]['password'])

{

data.query['ishost'] = true;

accept(null, true);

}

// Passwords don't match, do not authenticate

else

{

data.query['ishost'] = false;

return accept("Invalid Password", false);

}

}

// No match found, add to DB then authenticate

else

{

client.query(

'INSERT INTO web_users (username, password) VALUES ("'+UserID+'", "'+hex_md5(data.query['password'])+'")', null);

data.query['ishost'] = "1";

accept(null, true);

}

client.end();

}

);

// Should never reach this

return accept("Hacking Attempt", false);

}

// Definitely should never reach this

return accept("Hacking Attempt", false);

});

});

写入data.querymake使其可以通过handhakeData访问。但是由于某种原因,它没有通过应用程序传递。任何帮助表示赞赏,谢谢。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值