HELP MYSQL LOGIN!
#1

Hey i need help y am making my own mysql login and register system here is the problem

i dont know how to make in mysql the login.. take password of the inputtext in dialog... take password of the sql database... and if passworddialog = passwordsql
LOGIN!!
and else ... kick the player...

here is my code i dont know the problem

Код:
if(dialogid == 2)
  {
    if(response == 1)
		{
			new query[128];
			format(query, sizeof(query), "SELECT %d FROM jugadores WHERE nombre = %d LIMIT 1", inputtext, pname);
			mysql_query(query);
			mysql_store_result();
			if(mysql_fetch_row(inputtext)==1)
				{
				  SendClientMessage(playerid, COLOR_LIGHTBLUE, "** Has Sido Logueado Correctamente.");
					return 1;
				}
				else
				{
				  SendClientMessage(playerid, COLOR_LIGHTBLUE, "** Contraseсa Incorrecta.");
				  Kick(playerid);
				}
		}
		else
		{
		  SendClientMessage(playerid, COLOR_LIGHTBLUE, "** Has Cancelado. Tienes que loguear Obligatoriamente.");
		  Kick(playerid);
		}
    return 1;
  }
Reply
#2

please help T_T i need this... how i can take the password of the mysql?
Reply
#3

well you can use mysql_num_row like if your query is SELECT * FROM `players` WHERE Name = '%s' AND Password = '%s' LIMIT 1",pName,pass);

ADDED: Or method 2, with strcmp.
pawn Код:
new sql[512], row[128];
format(sql, sizeof(sql), "SELECT Password FROM players where Name = %s", PlayerName);
mysql_query(sql);
mysql_store_result();
mysql_fetch_row(row);
new PlayerPassword[128];
strmid(PlayerPassword, row, 0, strlen(row), 255);
mysql_free_result();
Now
if(strcmp(inputtext, PlayerPassword, true) == 0) { Login ok} else{ Failed }.
Reply
#4

I dont understand pleas help me.. i need that can you give an example with my code?
Reply
#5

Well ok.

pawn Код:
if(dialogid == 2)
{
    if(response == 1)
    {
         new sql[128], row[128], PlayerName[128], PlayerPassword[128];
         GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
         format(sql, sizeof(sql), "SELECT Password FROM jugadores where Name = '%s'", PlayerName);
         mysql_query(sql);
         mysql_store_result();
         mysql_fetch_row(row);
         strmid(PlayerPassword, row, 0, strlen(row), 255);
         mysql_free_result();
            if(strcmp(inputtext, PlayerPassword, true) == 0)
            {
                  SendClientMessage(playerid, COLOR_LIGHTBLUE, "** Has Sido Logueado Correctamente.");
                  return 1;
            }
            else
            {
                  SendClientMessage(playerid, COLOR_LIGHTBLUE, "** Contraseсa Incorrecta.");
                  Kick(playerid);
            }
        }
        else
        {
          SendClientMessage(playerid, COLOR_LIGHTBLUE, "** Has Cancelado. Tienes que loguear Obligatoriamente.");
          Kick(playerid);
        }
    return 1;
  }
Like it.
Reply
#6

When i enter and i type my password... the game look like this



That.. and i cant spawn and do anything... i dont know the problem :S here is my code

Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
  new pname[MAX_PLAYER_NAME];
  GetPlayerName(playerid, pname, sizeof(pname));
  if(dialogid == 1)
  {
    if(response == 1)
		{
			new query[128];
  		format(query, sizeof(query), "INSERT INTO jugadores (nombre, pass) VALUES ('%s', '%s')", pname, inputtext);
		  mysql_query(query);
		  SendClientMessage(playerid, COLOR_LIGHTBLUE, "** Registro Finalizado. Has Sido Logueado Automaticamente.");
		}
		else
		{
		  SendClientMessage(playerid, COLOR_LIGHTBLUE, "** Has Cancelado. El Registro es Obligatorio.");
		  Kick(playerid);
		}
    return 1;
  }
	if(dialogid == 2)
	{
		if(response == 1)
		{
			new sql[128], row[128], PlayerName[128], PlayerPassword[128];
			GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
			format(sql, sizeof(sql), "SELECT password FROM jugadores where nombre = '%s'", PlayerName);
			mysql_query(sql);
			mysql_store_result();
			mysql_fetch_row(row);
			strmid(PlayerPassword, row, 0, strlen(row), 255);
			mysql_free_result();
			if(strcmp(inputtext, PlayerPassword, true) == 0)
			{
				SendClientMessage(playerid, COLOR_LIGHTBLUE, "** Has Sido Logueado Correctamente.");
				return 1;
			}
			else
			{
				SendClientMessage(playerid, COLOR_LIGHTBLUE, "** Contraseсa Incorrecta.");
				Kick(playerid);
			}
  		}
  	}
  	else
	{
 		SendClientMessage(playerid, COLOR_LIGHTBLUE, "** Has Cancelado. Tienes que loguear Obligatoriamente.");
  		Kick(playerid);
	}
	return 0;
}
Reply
#7

Well this is meaning that your dialog was not response. I not recommend use NUMBERS like 1 2 3 for dialogs. Use enums construction with Names for dialogs like

enum
{
LOGIN_DIALOG,
REGISTER_DIALOG
}

and then if(dialogid == LOGIN_DIALOG)
Reply
#8

thx .. but do you see my code? anything is bad there? anii return or something?

hoy i can do enum

Thx for ur help man
Reply
#9

Quote:
Originally Posted by Zafire2008
thx .. but do you see my code? anything is bad there? anii return or something?

hoy i can do enum

Thx for ur help man
Well about login must be ok. You can check just give after
if(dialogid == 2)
{
if(response == 1)
{
printf("Check done");


And then watch if it will print on console then problem with code in dialog if not then just doesn't response.
Reply
#10

ok.. problem is the code because in the console saids "Check Done"
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)