Database connection problem
Posted: 07 Jun 2010, 23:56
Hi, I am making an MMORPG game and I have had it working for a while, but with no accounts. I just had a breakthough today with getting my config file to connect to my database, and having it attempt to login using the usernames and passwords in the database. The only problem is... its not really working. For the passwords I am using encryption to make sure the passwords are safe, I am wondering if this would effect the login or does it not matter. The name of the table is users, and i have username and password for the information of the users. Here is my dbLogin.as
When I run my game with the custom login turned on, this is the responce I get from the server in the output box.
I noticed that it says logKO, which means it isnt working but I dont know why, so what is wrong with this setup? Oh and here is my onExtentionResponce.
So what is wrong with the coding? And if you know how, could you post the complete code for the dblogin.as or the complete code for the onExtentionResponce, that would be great thanks!
Code: Select all
function init() {
dbase = _server.getDatabaseManager();
}
function destroy(){
//trace("dbLogin extension Closed");
}
function handleRequest(cmd, params, user, fromRoom){
trace("XT Message received: User: " & user & "\n Room: " & fromRoom & "\n Command: " & cmd); //We don't need any requests
}
function handleInternalEvent(evt) {
if (evt.name == "loginRequest") {
trace("recieved event");
var error = "";
var nick = evt["nick"].toLowerCase();
nick = _server.escapeQuotes(nick);
var pass = evt["pass"];
pass = _server.escapeQuotes(pass);
var chan = evt["chan"]; //Remove this, and the sky will fall on your head
var qRes = dbase.executeQuery("SELECT * FROM users WHERE password='"+pass+"' AND username = '"+nick+"' LIMIT 1;");
if (qRes != null) {
for (var i = 0; i<qRes.size(); i++) {
var row = qRes.get(i);
if(row['password'] == pass){
error = "";
} else {
error = "Incorrect Password";
}
}
} else {
error = "Invalid User";
}
var res = new Object();
if(error != ""){
res._cmd = "logKO";
trace("Login of user:"+nick+" failed. Reason:"+error)
} else {
var login = _server.loginUser(nick, pass);
if(login.success){
error = "";
res._cmd = "logOK";
} else {
error = login.error;
}
res.err = error;
}
_server.sendResponse(res,-1,null,chan);
} //END FIRST BLOCK. DO NOT REMOVE
} //DO NOT REMOVE ME EITHER
Code: Select all
[Sending]: <msg t='sys'><body action='verChk' r='0'><ver v='140' /></body></msg>
[Received]: <cross-domain-policy><allow-access-from domain="*" to-ports="9339" /></cross-domain-policy>
[Received]: <msg t="sys"><body action="apiOK" r="0" /></msg>
[Sending]: <msg t='sys'><body action='login' r='0'><login z='Turtles'><nick><![CDATA[Billybob]]></nick><pword><![CDATA[7649d532412dcc7c6d76658f21eb64db]]></pword></login></body></msg>
[Received]: <msg t="xt"><body action="xtRes" r="-1"><dataObj><var n='_cmd' t='s'>logKO</var></dataObj></body></msg>Code: Select all
smartfox.onExtensionResponse = function(resObj:Object) {
if (resObj._cmd == "logOK") {
// Login Success Example Code
_global.myName = resObj.name
gotoAndStop("chat")
} else if (resObj._cmd == "logKO") {
// Login failed example code
_gloabl.isBusy = true
status_txt.text = "Something has gone wrong. Please refresh the page and try logging in again.";
}
}