04.02.2012, 18:30
Ok so i want the passwords to be hashed... But it aint working this is my code:
Register dialog part:
Dialog login
Thanks in advance
Register dialog part:
pawn Код:
Dialog_Register(playerid, response, inputtext[])
{
switch(response)
{
case 1:
{
new hashPassword[129];
if(AccountExists[playerid])
return SendClientMessage(playerid, 0xFF0000, "[ACCOUNT] You're already registered!");
if(APlayerData[playerid][PlayerLogged] == 1)
return SendClientMessage(playerid, 0xFF0000, "[ACCOUNT] You're already logged in!");
if(strlen(inputtext) < 3 || strlen(inputtext) >= 32)
return SendClientMessage(playerid, 0xFF0000, "[ACCOUNT] Your password is too short or too long!");
CheckMySQL();
new string[128];
WP_Hash(hashPassword, 129, inputtext);
format(string, sizeof(string), "INSERT INTO Users (Name,Password) VALUES ('%s','%s')", APlayerData[playerid][Name], inputtext);
mysql_query(string);
AccountExists[playerid] = 1;
SendClientMessage(playerid, 0xFF0000, "[ACCOUNT] Your account has been created, please login now!");
ShowPlayerDialog(playerid, DialogLogin, DIALOG_STYLE_PASSWORD, "Welcome to European Roleplay", "Welcome to ER please login in order to play", "Login", "Cancel");
}
case 0:
{
Kick(playerid);
}
}
return 1;
}
pawn Код:
Dialog_Login(playerid, response, inputtext[])
{
switch(response)
{
case 1:
{
if(!AccountExists[playerid])
return SendClientMessage(playerid, 0xFF0000, "[ACCOUNT] You're not registered!");
if(APlayerData[playerid][PlayerLogged] == 1)
return SendClientMessage(playerid, 0xFF0000, "[ACCOUNT] You're already logged in!");
if(strlen(inputtext) < 3 || strlen(inputtext) >= 32)
{
SendClientMessage(playerid, 0xFF0000, "[ACCOUNT] Your password is too short or too long!");
Kick(playerid);
}
CheckMySQL();
new string[128], hashPassword[129];
format(string, sizeof(string), "SELECT * FROM Users WHERE Name = '%s' AND Password = '%s'", APlayerData[playerid][Name], inputtext);
mysql_query(string);
mysql_store_result();
if(!mysql_num_rows())
return SendClientMessage(playerid, 0xFF0000, "[ACCOUNT] Incorrect password!"), Kick(playerid);
WP_Hash(hashPassword, 129, inputtext);
new row[128]; // The length of 1 'row' total.
new field[14][128]; // [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.
APlayerData[playerid][Name] = strval(field[1]);
format(APlayerData[playerid][Password], 32, "%s", field[2]);
APlayerData[playerid][Admin] = strval(field[3]);
APlayerData[playerid][Money] = strval(field[4]);
APlayerData[playerid][X] = strval(field[5]);
APlayerData[playerid][Y] = strval(field[6]);
APlayerData[playerid][Z] = strval(field[7]);
APlayerData[playerid][Rot] = strval(field[8]);
APlayerData[playerid][Score] = strval(field[9]);
APlayerData[playerid][Points] = strval(field[10]);
format(APlayerData[playerid][pAccent], 19, "%s", field[11]);
APlayerData[playerid][Houses] = strval(field[12]);
APlayerData[playerid][Paydays] = strval(field[13]);
GivePlayerMoney(playerid, APlayerData[playerid][Money]);
SetPlayerScore(playerid, APlayerData[playerid][Score]);
format(string, sizeof(string), "[ACCOUNT] Welcome back %s, you are now logged in!", APlayerData[playerid][Name]);
SendClientMessage(playerid, 0xFF0000, string);
APlayerData[playerid][PlayerLogged] = 1;
}
case 0:
{
Kick(playerid);
}
}
return 1;
}