I want to login into my program via MySQL (Database).
string username = textBox1.Text.ToString();
int UserID = DB.runRead("SELECT id FROM users WHERE username='" + DB.Stripslash(username) + "'", null);
if (UserID > 0)
{
String[] UserData = DB.runReadRow("SELECT id, username, password, salt, rank, verein FROM benutzer WHERE id=" + UserID.ToString());
if(UserData[1].ToString().ToLower() == textBox2.Text.ToString().ToLower())
{
// logged in
SetStatusText("logged in!! :)");
SetProgressbarValue(100);
ButtonActivity(0, false);
}
else
{
// Password wrong
SetStatusText("wrong pw!!");
SetProgressbarValue(50);
}
}
else
{
SetStatusText("unregistered!!");
SetProgressbarValue(0);
}
I use this method on some other projects. Always working fine, but this time, the statement
if(UserID > 0)
and it's following code won't run, due to UserID
having a value of 0, and I don't know why. Of course there is a user in the Database:
I already tried to use another database (new created), but the error stays, so I think I did something stupid within the code. If necessary I could post the code of the working one, but I see no difference.
int UserID = DB.runRead("SELECT id FROM benutzer WHERE username='" + DB.Stripslash(Connection.Username) + "'", null);
if (UserID > 0)
{
string[] UserData = DB.runReadRow("SELECT id, username, password, salt, online, nickname, rank, firstlogin, bantime, anticheat FROM users WHERE id=" + UserID.ToString());
//Password = hashMD5(hashMD5(getBlock(3).ToLower()) + hashMD5(UserData[1]));
if (UserData[2].ToLower() == Password && UserData[9].ToString() == "1")
{
if (BanManager.isBlocked(UserID) == false /*&& RankManager.HasPermision(int.Parse(UserData[6]), "account.authorize")*/)
{
if (UserData[4].Equals("1"))
{
ReturnValue = LoginState.AlreadyLoggedIn;
Connection.send(new PACKET_SERVER_LIST(PACKET_SERVER_LIST.errorCodes.AlreadyLoggedIn));
//Log.WriteLine("Connection from " + Connection.IPAddress + " logged succesfull in as " + UserData[5] + " but the user is already online.");
Log.WriteLine("- Login - A Connection was successfully approved");
Log.WriteLine("- Login - IP Address: " + Connection.IPAddress + ",");
Log.WriteLine("- Login - Nickname: " + UserData[5] + ",");
Log.WriteLine("- Login - Status: The User is already logged in.");
Console.ForegroundColor = ConsoleColor.DarkCyan; Console.WriteLine(new String('*', Console.WindowWidth)); Console.ForegroundColor = ConsoleColor.Gray;
}
And so on. What's wrong?