Mysql and MD5 hash problem
#1

Hi! I made a login/register system whit mysql plugin for samp, I've used *****'s include for make MD5 hash but sometime my code do not work. When the user insert the password in the dialog the code stops before "LoginPlayer()", and the Login don't work, but other query work correctly, for example:
Код:
new Arma1,Arma2,Arma3,tmpstring[20];
	new valori[256];
  format(query,128,"SELECT * FROM account WHERE Username='%s'",PName(playerid));
	samp_mysql_query(query);
	samp_mysql_store_result();
	if(samp_mysql_fetch_row(valori))
	{
 		samp_mysql_get_field("Arma1", tmpstring);
		Arma1=strval(tmpstring);
 		samp_mysql_get_field("Arma2", tmpstring);
 		Arma2=strval(tmpstring);
 		samp_mysql_get_field("Arma3", tmpstring);
 		Arma3=strval(tmpstring);
	}

	GivePlayerWeapon(playerid,Arma1,500);
	GivePlayerWeapon(playerid,Arma2,500);
	GivePlayerWeapon(playerid,Arma3,500);
	
	
	format(query,128,"UPDATE account SET Skin = '%d' WHERE Username = '%s'",GetPlayerSkin(playerid),PName(playerid));
	samp_mysql_query(query);
can you help me? this is the surce code:
onplayerrequestclass

Код:
if(!IsLoggedIn[playerid])
	{
		new query[256],resultline[256];
	  format(query,sizeof(query),"SELECT * FROM account WHERE Username ='%s'",PName(playerid));
	  samp_mysql_query(query);
	  samp_mysql_store_result();
	  if(samp_mysql_fetch_row(resultline))
	  {
      samp_mysql_get_field("Indirizzoip", PlayerIP[playerid]) ;
	    if(!strcmp(PlayerIP[playerid],GetPlayerAddres(playerid),true) && Loginauto[playerid])
			{
				new rps[100];
				format(rps,100,"AUTO LOGIN: Indirizzo IP: [%s/%s]",PlayerIP[playerid],GetPlayerAddres(playerid));
				SendClientMessage(playerid,COLOR_GREY,rps);
				LoginPlayer(playerid);
			}else{
		    new str[150];
		    format(str,150,"Benvenuto %s\nInserisci la tua password",PlayerName[playerid]);
		    ShowPlayerDialog(playerid,LOGIN_DIALOG,DIALOG_STYLE_INPUT,"Login",str,"Login","Annulla");
			}
		}
		else
		{
		 	ShowPlayerDialog(playerid,REGISTER_DIALOG,DIALOG_STYLE_INPUT ,"Register","Non hai un account su questo server.\nRegistrati inserendo una password.", "Register","Annulla");
		}
	}
ondialogresponse:

Код:
if(dialogid==LOGIN_DIALOG)
	{
	  if(response)
	  {
	    new valori[128], reale[100], query[128];
			format(query,128,"SELECT * FROM account WHERE Username='%s'",PName(playerid));
			samp_mysql_query(query);
			samp_mysql_store_result();
 			samp_mysql_fetch_row(valori);
			samp_mysql_get_field("Password", reale);
			if(!strcmp(reale,MD5_Hash(inputtext),true))
			{
			  LoginPlayer(playerid);
			}else{
			  new msg[128];
			  PWErrata[playerid]+=1;
			  format(msg,sizeof(msg),"Password errata [%d/3]",PWErrata[playerid]);
			  ShowPlayerDialog(playerid,LOGIN_DIALOG,DIALOG_STYLE_INPUT,"Login",msg,"Login","Annulla");
        if(PWErrata[playerid]==3)
      	{
          SendClientMessage(playerid,COLOR_RED,"Hai sbagliato la password 3 volte.");
          Kick(playerid);
          format(msg,sizeof(msg),">> %s и stato kickato dal server per non aver effettuato correttamente il login",PName(playerid));
          SendClientMessageToAll(COLOR_RED,msg);
        }
			}

	  }
	}
Код:
forward LoginPlayer(playerid);
public LoginPlayer(playerid)
{
	new query[128],valori[256];
	format(query,128,">> Login effettuato correttamente.");
  IsLoggedIn[playerid] = true;
  SendClientMessage(playerid,0x00ff00aa,query);
  format(query,128,"SELECT * FROM account WHERE Username='%s'",PName(playerid));
	samp_mysql_query(query);
	samp_mysql_store_result();
	samp_mysql_fetch_row(valori);
	new tmpstr[256];
 	samp_mysql_get_field("Admin", tmpstr);
	AdminLevel[playerid]=strval(tmpstr);
	samp_mysql_get_field("Score",tmpstr);
	Score[playerid]=strval(tmpstr);
	samp_mysql_get_field("Entrata", tmpstr);
	Entrata[playerid]=strval(tmpstr);
	samp_mysql_get_field("Money", tmpstr);
	Money[playerid]=strval(tmpstr);
	samp_mysql_get_field("Skin", tmpstr);
	SetPlayerSkin(playerid,strval(tmpstr));
	SetSpawnInfo(playerid,0,strval(tmpstr),-2421.1748,334.7039,35.4517,240.8429,0,0,0,0,0,0);
	samp_mysql_get_field("Morti", tmpstr);
	Death[playerid]=strval(tmpstr);
	samp_mysql_get_field("Uccisioni", tmpstr);
	Kill[playerid]=strval(tmpstr);
	samp_mysql_get_field("AutoRepair", tmpstr);
	AutoRepair[playerid]=strval(tmpstr);
  samp_mysql_get_field("SpeedBoost", tmpstr);
	SpeedBoost[playerid]=strval(tmpstr);
	samp_mysql_get_field("ASK", tmpstr);
	AntiSpawnKill[playerid]=strval(tmpstr);
	samp_mysql_get_field("Loginauto", tmpstr);
	Loginauto[playerid]=strval(tmpstr);
	samp_mysql_get_field("DefaultSpawn", tmpstr);
	DefaultSpawn[playerid]=strval(tmpstr);
	
	

  format(query,200,"UPDATE account SET Indirizzoip = '%s' WHERE Username = '%s'",GetPlayerAddres(playerid),PName(playerid));
	samp_mysql_query(query);
			
	format(query,200,"UPDATE account SET ENTRATA = '%d' WHERE Username = '%s'",Entrata[playerid]+1,PName(playerid));
	samp_mysql_query(query);
	new msg[200];
	format(msg,200,"Ciao %s! Benvenuto nel server!",PlayerName[playerid]);
	SendClientMessage(playerid,COLOR_RED,"***********************************************************************************************************************************");
	SendClientMessage(playerid,COLOR_WHITE,msg);
	if(AdminLevel[playerid]>0)
	{
		format(msg,200,"Ti sei loggato come admin di livello %d",AdminLevel[playerid]);
		SendClientMessage(playerid,COLOR_WHITE,msg);
	}
	format(msg,200,"Hai $%d, e sei di livello: %d, entrata n°: %d",Money[playerid],Score[playerid],Entrata[playerid]);
	SendClientMessage(playerid,COLOR_WHITE,msg);
	SendClientMessage(playerid,COLOR_WHITE,"Gamemode in fase di sviluppo, al termine verranno azzerati tutti i dati degli utenti.");
	SendClientMessage(playerid,COLOR_WHITE,"Accedi al tuo pannello di controllo account su WWW.TLK.GAMEHOSTING.IT inserendo i dati del server.");
	SendClientMessage(playerid,COLOR_WHITE," ");
	SendClientMessage(playerid,COLOR_RED,"***********************************************************************************************************************************");
}
Table structure

PHPMA screen

[TLK]StanleY=me
[TLK]Flash=my brother



this work whit my computer but, in my brother's computer no.

i can't resolve this problem please help me!
Reply
#2

up
Reply
#3

Use MySQL's MD5 function not separate include and password is not text, but varchar(32)
Reply
#4

ok --> http://megahost.altervista.org/_altervista_ht/form.jpg

how can I use MySQL's MD5 function on pawn?
Reply
#5

It's MySQL function, so you cannot use it in pawn obviously .

Connect tables via IDs rather by names, so you can change names however you want and it won't get messed up.
Then under OnPlayerRequestClass or something get account ID.
Quote:

SELECT acc_id FROM account WHERE Username='%s'

If you get any results account exists if no then it doesn't.
And then get data from account.
Код:
SELECT * FROM account WHERE Username='%s' AND Password=MD5('%s')
If you get results password was right otherwise no.

And don't forget to escape password to prevent SQL injections. And next time ask in plugin's topic if you have issues with MySQL.
Reply
#6

ok i changed my code in:

Код:
if(dialogid==LOGIN_DIALOG)
	{
	  if(response)
	  {
			new valori[128], query[128], escaped[51];
	    samp_mysql_real_escape_string(inputtext, escaped);
			format(query,128,"SELECT * FROM account WHERE Username='%s' AND Password=MD5('%s')",PName(playerid),escaped);
			samp_mysql_query(query);
			samp_mysql_store_result();
			
 			if(samp_mysql_fetch_row(valori))
 			{
			  LoginPlayer(playerid);
			}else{
			  new msg[128];
			  PWErrata[playerid]+=1;
			  format(msg,sizeof(msg),"Password errata [%d/3]",PWErrata[playerid]);
			  ShowPlayerDialog(playerid,LOGIN_DIALOG,DIALOG_STYLE_INPUT,"Login",msg,"Login","Annulla");
        if(PWErrata[playerid]==3)
      	{
          SendClientMessage(playerid,COLOR_RED,"Hai sbagliato la password 3 volte.");
          Kick(playerid);
          format(msg,sizeof(msg),">> %s и stato kickato dal server per non aver effettuato correttamente il login",PName(playerid));
          SendClientMessageToAll(COLOR_RED,msg);
        }
			}

	  }
	}
Код:
if(dialogid==REGISTER_DIALOG)
	{
		if(response)
		{
		  if(!strlen(inputtext)) 	return ShowPlayerDialog(playerid,REGISTER_DIALOG,DIALOG_STYLE_INPUT ,"Errore","Non hai inserito alcuna password.", "Register","Annulla");
		  if(strlen(inputtext)<5)	return ShowPlayerDialog(playerid,REGISTER_DIALOG,DIALOG_STYLE_INPUT ,"Errore","Inserisci una password \ndi almeno 6 caratteri.", "Register","Annulla");
			if(strlen(inputtext)>25)return ShowPlayerDialog(playerid,REGISTER_DIALOG,DIALOG_STYLE_INPUT ,"Errore","Inserisci una password \ndi inferiore di 25 caratteri.", "Register","Annulla");
			
			
		  new query[164];
      new escaped[51];
	    samp_mysql_real_escape_string(inputtext, escaped);
		  format(query,128,"INSERT INTO `account` (Username,Password,Entrata,Score,Admin,Nome) VALUES ('%s',md5('%s'),0,0,0,'none')",PName(playerid),escaped);
		  samp_mysql_query(query);
		  ShowPlayerDialog(playerid,NAME_DIALOG,DIALOG_STYLE_INPUT,"Register","Inerisci il tuo nome","Avanti","X");
		  
			return 1;
		}else{
		  ShowPlayerDialog(playerid,REGISTER_DIALOG,DIALOG_STYLE_INPUT ,"Login","Non hai un account su questo server.\nRegistrati inserendo una password.", "Register","Annulla");
		}
	}
But I did not understand how i can connect tables via IDs, can you do an example for me?

thx
Reply
#7

help me! some user continue to report this error з_з
Reply
#8

up
Reply
#9

up
Reply
#10

i understood my error, when the player disconnect from the server, the script, saved a ratio, but sometimes the string's len of the ratio was 0.

But sometimes happens that the password has requested two times or more... i can't fix it, can you help me?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)