SA-MP Forums Archive
MySQL help me please. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: MySQL help me please. (/showthread.php?tid=408488)



MySQL help me please. - PaulDinam - 18.01.2013

Hello, I made this code. but when i add the IP insert it doesn't work, but without IP it works.

Код:
stock CreateAccount(playerid, salt[], pass[129])
{
	new query[240], escapedPlayerName[MAX_PLAYER_NAME], IP[16];
	mysql_real_escape_string(GetName2(playerid), escapedPlayerName);
	GetPlayerIp(playerid, IP, sizeof(IP));
	format(query, sizeof(query), "INSERT INTO `users` (name, salt, password, IP) VALUES (\'%s\', \'%s\', \'%s\', \'%s\')",escapedPlayerName,salt,pass,IP);
	mysql_function_query(dbHandle, query, false, "OnAccountCreate", "d", playerid);
}
what is the problem with the IP?


Re: MySQL help me please. - AndreT - 18.01.2013

I did not bother to dig too deep, but why are you escaping single quotes? They are necessary for the query, yet don't have an effect inside the string for PAWN.

Remove the escape characters (\).


Re: MySQL help me please. - PaulDinam - 18.01.2013

still the same problemo.

mysql debug

Код:
[16:28:32] Passing query INSERT INTO `users` (name, salt, password, IP) VALUES ('Vincent_Leighton', '0IN1757sEA588tt87p53756u82G9As', '463AF90AAE11771CF943309984E6594837231F2DD0B641DB338C8B01B7370E2C906EEC129A9FA33B64678D087D3E0CD6AD5E6121D28498B4D6C3F70137C00441' | d
[16:28:32] CMySQLHandler::ProcessQueryThread() - Error will be triggered to OnQueryError()



Re: MySQL help me please. - LarzI - 18.01.2013

Your query string isn't big enough.

You have to increase the cells. With name, password and IP, you will (on maximum) reach 247 cells. There's already 7 cells to much, and you still need to add salt into there. I have no idea what salt is - honestly - but I know it requires space.


Re: MySQL help me please. - PaulDinam - 18.01.2013

SO WHAT SHOULD i DO THEN?


Re: MySQL help me please. - Roel - 18.01.2013

set new query[240] to new query[1024] for example.
And why are you not using SHA1() to hash passwords?
Anyway try to set the string larger.


Re: MySQL help me please. - LarzI - 18.01.2013

Quote:
Originally Posted by Roel
Посмотреть сообщение
set new query[240] to new query[1024] for example.
And why are you not using SHA1() to hash passwords?
Anyway try to set the string larger.
Isn't 1024 a bit over the top? He only needs 247 + whatever the maximum length of salt[] is - which I have no knowledge of - which I believe won't be over 200 cells big.


Re: MySQL help me please. - PaulDinam - 18.01.2013

Kay, fixed it:

format(query, sizeof(query), "INSERT INTO `users` (name, password, playerIP) VALUES ('%s', SHA1('%s'), '%s')",escapedPlayerName,pass,IP);

last question:
how do i check if input in dialog is SHA1??..


Re: MySQL help me please. - LarzI - 18.01.2013

You hash inputtext with SHA1 and then compare the result with the hashed password in the database.


Re: MySQL help me please. - PaulDinam - 18.01.2013

thank you guys for the help.