[MSQL] Need help checking if password is right.
#1

Hello, so i am trying to create a register, login system. I made the register and it works fine, it shows my nickname in database and password that i set, but i am having problems with login, because i don't really know how to check if the password is correct that you typed compared to password in the database. Here's the script:

Код:
if(dialogid == 200)
	{
	    if(response)
	    {
	        new vardas[MAX_PLAYER_NAME];
	        if(!strlen(inputtext)) return ShowPlayerDialog(playerid,200,DIALOG_STYLE_INPUT,"{A3E4FF}Prisijungimas","{FFFFFF}Jus neivedete slaptazodzio.\n{FFFFFF}Prasome ivesti slaptazodi, kad galetumete prisijungti.","Prisijungti","Atsaukti");
 			if(strlen(inputtext) < 3 || strlen(inputtext) >= 32)
	    	return ShowPlayerDialog(playerid,200,DIALOG_STYLE_INPUT,"{A3E4FF}Prisijungimas","{FFFFFF}Slaptazodis yra per trumpas arba per ilgas.\n{FFFFFF}Prasome ivesti teisinga slaptazodi, kad galetumete prisijungti!","Prisijungti","Atsaukti");
			CheckMySQL();
    		new string[128];
			format(string, sizeof(string), "SELECT * FROM Saskaitos WHERE Vardas = '%s' AND Slaptazodis = '%s'", vardas, inputtext);
			mysql_query(string);
			mysql_store_result();
			if(mysql_num_rows())
			{
			    prisijunges[playerid] = 1;
				SendClientMessage(playerid, geltona, "[FunZoneLT]>> Jus prisijungete! Sekmes zaidime jums linki Administracijos komanda!");
				GivePlayerMoney(playerid, -50000);
				if(ALygis[playerid] >= 1)
  				{
  		    		Alabel[playerid] = Create3DTextLabel("Administratorius", raudona,30.0,40.0,50.0,40.0,0);
    				Attach3DTextLabelToPlayer(Alabel[playerid], playerid, 0.0, 0.0, 0.7);
				}
			}
			else
			{
				ShowPlayerDialog(playerid,200,DIALOG_STYLE_INPUT,"{A3E4FF}Prisijungimas","{FFFFFF}Jus ivedete neteisinga slaptazodi.\n{FFFFFF}Prasome ivesti teisinga slaptazodi, kad galetumete prisijungti!","Prisijungti","Atsaukti");
				return 1;
			}
			new row[128];
			new field[7][32]; // [4] = Amount of fields, [24] = Max length of the bigest field.
			mysql_fetch_row_format(row, "|");
			explode(row, field, "|");
			mysql_free_result();
			// The field starts here with 1, because the field 'Name' = 0, and we already have the name in a variable.
			format(ZStats[playerid][Slaptazodis], 32, "%s", field[1]);
 			ZStats[playerid][Adminas] = strval(field[2]);
 			ZStats[playerid][Pinigai] = strval(field[3]);
 			GivePlayerMoney(playerid, ZStats[playerid][Pinigai]);
		}
		else
		{
		    SendClientMessage(playerid, raudona, "[FunZoneLT]>> Jus turite prisijungti prie serverio, pries zaidziant!");
		    Kick(playerid);
		}
	}
I am new to MSQL, can anyone tell me where's the problem?
Reply
#2

you need php code that check password
Reply
#3

Could you give me an example?
Reply
#4

pawn Код:
if(mysql_num_rows() != 0)
        {
            //Correct Password
        }
        else
        {
            //Incorrect Password
        }
Reply
#5

It still, says that my password is wrong, and heres how i put the your thing in:
Код:
if(dialogid == 200)
	{
	    if(response)
	    {
	        new Pass = strval(inputtext);
	        //new vardas[MAX_PLAYER_NAME];
	        if(!strlen(inputtext)) return ShowPlayerDialog(playerid,200,DIALOG_STYLE_INPUT,"{A3E4FF}Prisijungimas","{FFFFFF}Jus neivedete slaptazodzio.\n{FFFFFF}Prasome ivesti slaptazodi, kad galetumete prisijungti.","Prisijungti","Atsaukti");
 			if(strlen(inputtext) < 3 || strlen(inputtext) >= 32)
	    	return ShowPlayerDialog(playerid,200,DIALOG_STYLE_INPUT,"{A3E4FF}Prisijungimas","{FFFFFF}Slaptazodis yra per trumpas arba per ilgas.\n{FFFFFF}Prasome ivesti teisinga slaptazodi, kad galetumete prisijungti!","Prisijungti","Atsaukti");
			CheckMySQL();
    		//new string[128];
    		new Query[200];
			format(Query, sizeof(Query), "SELECT * FROM `Saskaitos` WHERE `Vardas` = '%s' AND `Slaptazodis` = '%i'", GetPlayerEscapeName(playerid), Pass);
			mysql_query(Query);
			mysql_store_result();
			if(mysql_num_rows() != 0)
        	{
            	prisijunges[playerid] = 1;
				SendClientMessage(playerid, geltona, "[FunZoneLT]>> Jus prisijungete! Sekmes zaidime jums linki Administracijos komanda!");
				GivePlayerMoney(playerid, -50000);
				if(ALygis[playerid] >= 1)
  				{
  		    		Alabel[playerid] = Create3DTextLabel("Administratorius", raudona,30.0,40.0,50.0,40.0,0);
    				Attach3DTextLabelToPlayer(Alabel[playerid], playerid, 0.0, 0.0, 0.7);
				}
        	}
       	 	else
        	{
            	ShowPlayerDialog(playerid,200,DIALOG_STYLE_INPUT,"{A3E4FF}Prisijungimas","{FFFFFF}Jus ivedete neteisinga slaptazodi.\n{FFFFFF}Prasome ivesti teisinga slaptazodi, kad galetumete prisijungti!","Prisijungti","Atsaukti");
				return 1;
       	 	}
			new row[128];
			new field[7][32]; // [4] = Amount of fields, [24] = Max length of the bigest field.
			mysql_fetch_row_format(row, "|");
			explode(row, field, "|");
			mysql_free_result();
			// The field starts here with 1, because the field 'Name' = 0, and we already have the name in a variable.
			format(ZStats[playerid][Slaptazodis], 32, "%s", field[1]);
 			ZStats[playerid][Adminas] = strval(field[2]);
 			ZStats[playerid][Pinigai] = strval(field[3]);
 			GivePlayerMoney(playerid, ZStats[playerid][Pinigai]);
		}
		else
		{
		    SendClientMessage(playerid, raudona, "[FunZoneLT]>> Jus turite prisijungti prie serverio, pries zaidziant!");
		    Kick(playerid);
		}
	}
Anyone know what the problem is? ( Im new to MSQL
Reply
#6

Quote:
Originally Posted by Snipa
Посмотреть сообщение
pawn Код:
if(mysql_num_rows() != 0)
        {
            //Correct Password
        }
        else
        {
            //Incorrect Password
        }
...No... As far as I know, mysql_num_rows is used when the thing you put in query is found or not.
Use strcmp to compare passwords.
Reply
#7

Quote:
Originally Posted by Mean
Посмотреть сообщение
...No... As far as I know, mysql_num_rows is used when the thing you put in query is found or not.
Use strcmp to compare passwords.
There is no need for strcmp, that mysql_num_rows is just the right one.
You run your query like SELECT NULL FROM `table` WHERE `username` LIKE 'name' AND `password` = 'pass', which returns something only if there is row with same username and password.
Reply
#8

I think I found your problem too.
This isn't right way to deal with password: new Pass = strval(inputtext);
I'm not sure what that returns, but it definitely isn't what you should have.
Use some encrypt or hash instead.

EDIT: I tested what that returns and it is always 0 -not good.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)