10.07.2012, 11:14
Ok there is a few problems with what you've got going.
You're declaring the two arrays and then whirlpool hashing them, you should be using something like:
That way you're hashing the inputtext and putting the result into FinalPassword. There is also no need to escape the string after you have hashed the password because the whirlpool algorithm will not use those special characters.
So really all you need to do is change this:
To this:
There are still a few unexplained things, such as this:
No idea why you're storing it, unless you're using it for use later on, however that (as I am sure you know) will store the players unhashed password so you probably want to be careful what you do with that.
You can also condense down your MySQL register function now too, but if you wanted you could move the whirlpool hashing into the function instead of before calling it. Its all personal preference. (Although moving it back into the function may be a good idea as you're always going to need to hash the passwords).
That's the cleaned up code but not including the hashing in there.
As the user above also pointed out correctly, you need to change the size of the query string to be able to fit everything in there, I have changed it for you but its a fairly arbitrary value (I'm not going to count the cells even though I have little better to do).
pawn Код:
new escpass[129], FinalPassword[132], passwordstring[132];
WP_Hash(passwordstring, sizeof(passwordstring), FinalPassword);
pawn Код:
new FinalPassword[132];
WP_Hash(FinalPassword, sizeof(FinalPassword),inputtext);
So really all you need to do is change this:
pawn Код:
new escpass[129], FinalPassword[132], passwordstring[132];
WP_Hash(passwordstring, sizeof(passwordstring), FinalPassword);
mysql_real_escape_string(FinalPassword, escpass);
MySQL_Register(playerid, escpass);
pawn Код:
new FinalPassword[132];
WP_Hash(FinalPassword, sizeof(FinalPassword), inputtext);
MySQL_Register(playerid,FinalPassword);
pawn Код:
format(APlayerData[playerid][PlayerPassword], 50, "%s", inputtext);
You can also condense down your MySQL register function now too, but if you wanted you could move the whirlpool hashing into the function instead of before calling it. Its all personal preference. (Although moving it back into the function may be a good idea as you're always going to need to hash the passwords).
pawn Код:
stock MySQL_Register(playerid, const passwordstring[])
{
new query[350], pname[24], IP[16];
GetPlayerName(playerid, pname, MAX_PLAYER_NAME);
GetPlayerIp(playerid, IP, 16);
format(query, sizeof(query), "INSERT INTO PlayerData (Name, Password, Ip, PlayerLevel,Score,OFWarns) VALUES('%s', '%s','%s',0, 0, 0)", pname, passwordstring, IP);
mysql_query(query);
SendClientMessage(playerid, -1, "You have been registered on this server!");
return 1;
}
As the user above also pointed out correctly, you need to change the size of the query string to be able to fit everything in there, I have changed it for you but its a fairly arbitrary value (I'm not going to count the cells even though I have little better to do).