SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 16/01/2020, 05:14 PM   #1
Marko Koprivanac
Big Clucker
 
Marko Koprivanac's Avatar
 
Join Date: Feb 2012
Location: Belgrade,Serbia
Posts: 78
Reputation: 0
Default MySQL not updating password

I need help, updating player passwords won't work

Code:
UpdatePlayerPass(playerid, newpass[])
{
        for(new i = 0; i < 16; i++) Player[playerid][Salt][i] = random(94) + 33;
	SHA256_PassHash(newpass, Player[playerid][Salt], Player[playerid][Password], 64);

    mysql_format(g_SQL, query, sizeof query, "UPDATE `players` SET `Password` = %s, 'Salt' = %e WHERE `ID` = %d LIMIT 1", Player[playerid][Password],Player[playerid][Salt], Player[playerid][ID]);
	mysql_tquery(g_SQL, query);
	return 1;
}
While this code will work perfect:
Code:
UpdatePlayerKills(killerid, killNumber)
{
	if (killerid == INVALID_PLAYER_ID) return 0;
	if (Player[killerid][LoggedIn] == false) return 0;

	Player[killerid][Killovi] += killNumber;
    SetPlayerScore(killerid, GetPlayerScore(killerid) + killNumber);
    
	mysql_format(g_SQL, query, sizeof query, "UPDATE `players` SET `Killovi` = %d WHERE `ID` = %d LIMIT 1", Player[killerid][Killovi], Player[killerid][ID]);
	mysql_tquery(g_SQL, query);
	return 1;
}
I already tried to format query diffrent like this:
Code:
mysql_format(g_SQL, query, sizeof query, "UPDATE `players` SET `Password` = '%s', 'Salt' = '%e' WHERE `ID` = %d;", Player[playerid][Password],Player[playerid][Salt], Player[playerid][ID]);
Still same, ID is Primary key.

Database works, kills, money, deaths it all saves, but password and salt won't, i have no idea why, when i used print to debug everything has it's value but when i reconnect i can use old password and not new.
Help please and thanks in advance.
Marko Koprivanac is offline   Reply With Quote
Old 16/01/2020, 05:42 PM   #2
DRIFT_HUNTER
High-roller
 
Join Date: Oct 2009
Posts: 2,070
Reputation: 188
Default Re: MySQL not updating password

Check mysql log inside samp server folder. By the way, you should escape users input, that is password, you are escaping salt (that is probably generated by server).
__________________
Looking for someone to start drifting server, drop me a pm if you are interested.


Any PM's that include question about any kind of help will be ignored.
Use appropriate boards for that
DRIFT_HUNTER is offline   Reply With Quote
Old 16/01/2020, 05:54 PM   #3
Marko Koprivanac
Big Clucker
 
Marko Koprivanac's Avatar
 
Join Date: Feb 2012
Location: Belgrade,Serbia
Posts: 78
Reputation: 0
Default Re: MySQL not updating password

Quote:
Originally Posted by DRIFT_HUNTER View Post
Check mysql log inside samp server folder. By the way, you should escape users input, that is password, you are escaping salt (that is probably generated by server).
Yeah, my bad, it was set to %e but i tried to change to %s to see if that would help, thanks for pointing that out.
I forgot i have logs, here it is:

Code:
[17:25:44] [ERROR] error #1064 while executing query "UPDATE `players` SET `Password` = 'D22359BA78D5A600AB19B2BECFDE219109D660BEB75796D35585A39F5AD0458A', 'Salt' = '#O\'Cs:eiROrHnr)_' WHERE `ID` = 3;": You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''Salt' = '#O\'Cs:eiROrHnr)_' WHERE `ID` = 3' at line 1
[17:25:47] [ERROR] error #1064 while executing query "UPDATE `players` SET `Money` = 0, `BankMoney` = 0, `Health` = 100.000000, `Armor` = 0.000000, `X` = 2034.071167, `Y` = 1152.876221, `Z` = 10.820313, `Angle` = 2.505459, `Interior` = 0, 'Skin' = 294, 'Smrti' = 7, 'Killovi' = 16 WHERE `ID` = 3 LIMIT 1": You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''Skin' = 294, 'Smrti' = 7, 'Killovi' = 16 WHERE `ID` = 3 LIMIT 1' at line 1
I can't see what i did wrong
Here are the lines that are throwing errors:
Code:
mysql_format(g_SQL, query, sizeof query, "UPDATE `players` SET `Password` = '%e', 'Salt' = '%e' WHERE `ID` = %d;", Player[playerid][Password],Player[playerid][Salt], Player[playerid][ID]);
And why updating kills and deaths works but this does not?

EDIT: stupid me, not looking at logs, it says all there, i looked at manual and the problem was in using '
So correct way to do this would be:
Code:
mysql_format(g_SQL, query, sizeof query, "UPDATE players SET Password = %e, Salt = %e WHERE ID = %d", Player[playerid][Password],Player[playerid][Salt], Player[playerid][ID]);
No ' needed, i'll apply that to the whole gamemode now, thanks for helping.
Marko Koprivanac is offline   Reply With Quote
Old 16/01/2020, 05:58 PM   #4
Calisthenics
Gangsta
 
Join Date: May 2018
Posts: 948
Reputation: 167
Default Re: MySQL not updating password

Change 'Salt' to `Salt` or Salt. Using single quotes takes it as a literal string when it expected a column name.
__________________
Calisthenics is offline   Reply With Quote
Old 16/01/2020, 06:07 PM   #5
Marko Koprivanac
Big Clucker
 
Marko Koprivanac's Avatar
 
Join Date: Feb 2012
Location: Belgrade,Serbia
Posts: 78
Reputation: 0
Default Re: MySQL not updating password

Yeah, that was the problem, my bad, i'm begginer at MySQL not so much in pawn but mysql is new for me so i'm still learning, thank you very much.
Marko Koprivanac is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
I need help with updating mysql from R5 to R41-4 Edvukas Scripting Help 8 06/12/2019 12:24 PM
[MySQL] Not updating value. Sc0pion Scripting Help 1 10/06/2016 03:06 AM
MySQL Not Updating! RenovanZ Scripting Help 8 04/08/2013 12:19 AM
MySql Not Updating aqu Scripting Help 0 26/02/2012 03:46 PM
Updating Car [Mysql] Cameltoe Help Archive 10 14/08/2010 10:56 PM


All times are GMT. The time now is 07:47 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.