28.07.2015, 11:20
I'm having problem with Login/Register System. If a Player Register and then relog then he will be able to login. But When I Restart my Server then When a Player Connects then His Hashed Password Get Reset in his .ini saved file. What can be the problem?
PHP Code:
public OnPlayerConnect(playerid)
{
if(fexist(UserPath(playerid)))
{
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
new str[400];
format(str,sizeof(str),"{FFFFFF}This Account Name \"%s\" is registered in our server.\n\nIf You are the owner of the account then please Login\n\n",PlayerName(playerid));
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,"{0081FF}Login Panel",str,"Login","Quit");
SendClientMessage(playerid,yellow,"Welcome Back, Please Login To Access Your Account");
}
else
{
new str1[400];
format(str1,sizeof(str1),"{FFFFFF}Your Account Name \"%s\" is not registered. \n\nPlease register your password to save your status\n\nEnter the password Below:",PlayerName(playerid));
SendClientMessage(playerid,yellow,"Please Register Your Account");
ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT,"{0081FF}Registering Panel",str1,"Register","Quit");
}
PlayerPlaySound(playerid, 1027 , 0.0, 0.0, 10.0);
CamMove[playerid]=true;
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
SaveUser(playerid);
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
switch(dialogid)
{
case DIALOG_REGISTER:
{
if (!response) return Kick(playerid);
if(response)
{
if(strlen(inputtext)<6)
{
new str1[400];
format(str1,sizeof(str1),"{FFFFFF}Your Account Name \"%s\" is not registered. \n\nPlease register your password to save your status\n\nEnter the password Below:\n{B71800}Password must be 6 characters long\n\n",PlayerName(playerid));
ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT,"{007BBE}Registering Panel",str1,"Register","Quit");
}
new hashpass[129];
WP_Hash(hashpass,sizeof(hashpass),inputtext);
format(Player[playerid][password],129,hashpass);
Player[playerid][cash]=0;
Player[playerid][score]=0;
Player[playerid][kills]=0;
Player[playerid][deaths]=0;
Player[playerid][ADMIN]=0;
Player[playerid][VIP]=0;
Player[playerid][TP]=0;
Player[playerid][FBI]=0;
Player[playerid][terrorist]=0;
SaveUser(playerid);
}
}
case DIALOG_LOGIN:
{
if (!response) return Kick(playerid);
if(response)
{
if(!strlen(inputtext))
{
new str3[400];
format(str3,sizeof(str3),"{FFFFFF}This Account Name \"%s\" is registered in our server.\n\nIf You are the owner of the account then please Login\n\n",PlayerName(playerid));
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,"{007BBE}Login Panel",str3,"Login","Quit");
}
new hashpass[129];
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
WP_Hash(hashpass,sizeof(hashpass),inputtext);
if(!strcmp(hashpass,Player[playerid][password],false))
{
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
GivePlayerMoney(playerid, Player[playerid][cash]);
SetPlayerScore(playerid,Player[playerid][score]);
}
else
{
new str3[400];
format(str3,sizeof(str3),"{FFFFFF}This Account Name \"%s\" is registered in our server.\n\nIf You are the owner of the account then please Login\n\n{B71800}Password Incorrect",PlayerName(playerid));
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,"{007BBE}Login Panel",str3,"Login","Quit");
}
return 1;
}
}
}
return 1;
}
stock UserPath(playerid)
{
new string[128],playername[MAX_PLAYER_NAME];
GetPlayerName(playerid,playername,sizeof(playername));
format(string,sizeof(string),PATH,playername);
return string;
}
forward LoadUser_data(playerid,name[],value[]);
public LoadUser_data(playerid,name[],value[])
{
INI_String("Password", Player[playerid][password],129);
INI_Int("Cash",Player[playerid][cash]);
INI_Int("Score",Player[playerid][score]);
INI_Int("Kills",Player[playerid][kills]);
INI_Int("Deaths",Player[playerid][deaths]);
INI_Int("Admin",Player[playerid][ADMIN]);
INI_Int("VIP",Player[playerid][VIP]);
INI_Int("TP",Player[playerid][TP]);
INI_Int("FBI",Player[playerid][FBI]);
INI_Int("TERRORIST",Player[playerid][terrorist]);
return 1;
}
stock SaveUser(playerid)
{
new INI:File = INI_Open(UserPath(playerid));
INI_WriteString(File,"Password",Player[playerid][password]);
INI_WriteInt(File,"Cash",Player[playerid][cash]);
INI_WriteInt(File,"Score",Player[playerid][score]);
INI_WriteInt(File,"Kills",Player[playerid][kills]);
INI_WriteInt(File,"Deaths",Player[playerid][deaths]);
INI_WriteInt(File,"Admin",Player[playerid][ADMIN]);
INI_WriteInt(File,"VIP",Player[playerid][VIP]);
INI_WriteInt(File,"TP",Player[playerid][TP]);
INI_WriteInt(File,"FBI",Player[playerid][FBI]);
INI_WriteInt(File,"TERRORIST",Player[playerid][terrorist]);
INI_Close(File);
}
stock PlayerName(playerid)
{
new name[128];
GetPlayerName(playerid,name,sizeof(name));
return name;
}



