Hello.
I'm a beginner who just started coding for games.
While watching the YouTube video this time, I was making the unity login system into C# and MySQL DB.
It works normally in the video, but I don't know why it doesn't work on mine.ㅠ<
I analyzed the code a little bit and guessed that there was a little problem with this part. I'd appreciate it if you could judge after looking at it.
If I enter my ID and password in UNI.T login window
private void logInAccount(string userName, string p)
{
scObject data = new scObject("loginInfo");
data.addString("username", userName);
stringPass = calculateMD5Hash(p);//password encryption
data.addString("pass", p);
message mes = new message("login");
mes.addSCObject(data);
SendServerMessage(mes);
}
Unity login script sends the information I entered to the TCP server.
public void handleClientData(Socket cSock, message incObject)
{
switch(incObject.messageText)
{
case "login":
message newMessage = new message("loginResponse");
if (playerTools.checkLogin(incObject.getSCObject(0).getString("username"), incObject.getSCObject(0).getString("pass")))
{
scObject data = new scObject("data");
data.addBool("response", true);
newMessage.addSCObject(data);
}
else
{
scObject data = new scObject("data");
data.addBool("response", false);
newMessage.addSCObject(data);
}
sendClientMessage(cSock, newMessage);
break;
default:
output.outToScreen("The client sent a message: " + incObject.messageText);
break;
}
}
I receive the login message from UNI.T here and send the ID and password to checkLogin.
public static bool checkLogin(string username, string pass)
{
MySqlConnection con = database.getConnection();
MySqlCommand cmd = con.CreateCommand();
cmd.CommandText = "SELECT * FROM accounts WHERE account = '" + username + "' AND password = '" + pass + "' LIMIT 1;";
MySqlDataReader reader;
output.outToScreen("" + cmd.CommandText); //Additional part
bool result = false;
try
{
con.Open();
//output.outToScreen ("Open MySQL");
reader = cmd.ExecuteReader();
reader.Read();
if (reader.GetInt32("id") > 0)
{
result = true;
}
con.Close();
}
catch
{
con.Close();
//output.outToScreen ("Close MySQL");
}
return result;
}
I think checkLogin is not working properly. I've been looking at the code for three days and trying to google it, but I can't find the answer. I'd appreciate it if you could help me, masters!
I'll show you the next step.
switch (mes.messageText)
{
case "loginResponse":
Debug.Log(""+ mes.getSCObject(0).getBool("response"));//
Debug.Log("The login response returned: " + (mes.getSCObject(0).getBool("response") ?
"correct." : "not correct."));
break;
default:
Debug.Log("The server sent a message: " + mes.messageText);
break;
}
This is the part that receives the login information sent from the TCP server to show it to the client whether it is true or false, but it keeps showing false. ㅠ<
(P.S. I may have made a wrong DB, so I will attach the DB picture together.)
Have you tried debugging with a debugger?
Developers are in trouble if they make a guess. You have to talk about data, that's the basis.
First of all, it's hard to know why it's not possible with the data given.
However, if the checkLogin method is not available, there is one thing that is suspicious.
Whether you can access mysql at ado.net.
Mysql is blocked by default for remote connections.
First, check mysql connection to ado.net.
© 2024 OneMinuteCode. All rights reserved.