SA-MP Forums Archive
passwords seems to be wrong after registering - 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: passwords seems to be wrong after registering (/showthread.php?tid=629277)



[Y_ini]passwords seems to be wrong after registering[SOLVED] - grymtn - 23.02.2017

topic can be locked problem wasnt in these blocks release was broken udb hash is used

entering game and after registering my passwords dont seem to work as it constantly says wrong password i thought it was because of udb hash so i removed the hash from code and doesnt seem like answer. Code is not mine im just editing a release and im not perfect with coding iin pwn please bear with me

im using y_ini

Edit: Apparently when i leave my password empty and try to login like that i can login like correct password. so entering the actual password doesnt work but leaving it blank logs me in

my code blocks
Код:
        case DIALOG_REGISTER:
        {
      		if (!response)
            {
                Kick(playerid);
                return 1;
            }
            else if(response)
            {
                if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Register","You have entered an invalid password.\n""Type your password below to register a new account.","Register","Quit");
                new IP[22];
                GetPlayerIp(playerid, IP, sizeof(IP));
                new name[MAX_PLAYER_NAME];
    			GetPlayerName(playerid, name, sizeof(name));
    			
    			PlayerInfo[playerid][pName] = name;
    			PlayerInfo[playerid][pPlate1] = 0;
    			PlayerInfo[playerid][pPlate2] = 0;
    			PlayerInfo[playerid][pPlate3] = 0;
                new INI:File = INI_Open(UserPath(playerid));
                INI_SetTag(File,"data");
                INI_WriteInt(File,"Password");
                INI_WriteInt(File,"Cash",0);
                INI_WriteInt(File,"Admin",0);
                INI_WriteInt(File,"Kills",0);
                INI_WriteInt(File,"Deaths",0);
                INI_WriteInt(File,"LSD",0);
                INI_WriteInt(File,"Cocaine",0);
                INI_WriteInt(File,"Marijuana",0);
                INI_WriteInt(File,"Respect",0);
                INI_WriteInt(File,"Cigarettes",0);
                INI_WriteInt(File,"Beer",0);
                INI_WriteString(File, "Ip", IP);
                INI_WriteFloat(File,"Health",0);
                INI_WriteInt(File,"BankAccount",0);
                INI_WriteInt(File,"Datasaved",0);
                INI_WriteInt(File,"Number",0);
                INI_WriteInt(File,"Level",0);
                INI_WriteInt(File,"Crashed",0);
                INI_WriteInt(File,"Phone",0);
                INI_WriteInt(File,"Donator",0);
				INI_WriteInt(File, "Plate1", PlayerInfo[playerid][pPlate1]);
				INI_WriteInt(File, "Plate2", PlayerInfo[playerid][pPlate2]);
				INI_WriteInt(File, "Plate3", PlayerInfo[playerid][pPlate3]);
   				INI_WriteString(File, "Name", PlayerInfo[playerid][pName]);
                INI_Close(File);
				
      			FadeColorForPlayer(playerid,0,0,0,0,0,0,0,255,15,0);
                GivePlayerMoney(playerid, 2500);
                PlayerInfo[playerid][pSkin] = 26;
                PlayerInfo[playerid][pXPos] = 1742.9600;
                PlayerInfo[playerid][pYPos] = -1861.4019;
                PlayerInfo[playerid][pZPos] = 0.2426;
                PlayerInfo[playerid][pLevel] = 1;
                PlayerInfo[playerid][pBankAccount] = 1000;
                SetTimerEx("AgeSetup", 1000, false, "i", playerid);
                new Year, Month, Day;
				getdate(Year, Month, Day);
				PlayerLogged[playerid] = true;
				PlayerInfo[playerid][pYear] = Year;
				PlayerInfo[playerid][pMonth] = Month;
				PlayerInfo[playerid][pDay] = Day;
            }
        }
Код:
        case DIALOG_LOGIN:
        {
      		if(!response)
            {
                Kick(playerid);
                return 1;
            }
            else if(response)
            {
                if(strlen(inputtext) == PlayerInfo[playerid][pPass])
                {
                    INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
                    GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
                    LoadFightingStyle(playerid);
                   	FadeColorForPlayer(playerid,0,0,0,255,0,0,0,0,15,0);
                    SCM(playerid, COLOR_WHITE, "You have successfully logged in.");
                    TogglePlayerSpectating(playerid, false);
                    PlayerLogged[playerid] = true;
                    SetPlayerScore(playerid, PlayerInfo[playerid][pLevel]);
              		new playername[24];
					GetPlayerName(playerid, playername, sizeof(playername));
					
					PlayerInfo[playerid][pName] = playername;
					
					new INI:File = INI_Open(UserPath(playerid));
					INI_SetTag(File,"data");
					INI_WriteString(File, "Name", PlayerInfo[playerid][pName]);
					INI_Close(File);
					
					sInfo[playerid][Misc] = 0;
					sInfo[playerid][Head] = 0;
					sInfo[playerid][Chest] = 0;
					sInfo[playerid][Crotch] = 0;
					sInfo[playerid][LArm] = 0;
					sInfo[playerid][RArm] = 0;
					sInfo[playerid][LLeg] = 0;
					sInfo[playerid][RLeg] = 0;
					
					if(PlayerInfo[playerid][pTutorialDone] == 0) return SetTimerEx("AgeSetup", 1000, false, "i", playerid);
					
                   	if(PlayerInfo[playerid][pBanned] == 1)
					{
					    SCM(playerid, COLOR_LIGHTRED, "AdmCmd: You have been banned for logging into a banned account.");
    					SetTimerEx("UnsetBan", 500, 0, "i", playerid);
					}
                }
                else
                {
                    ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,"Login","You have entered an incorrect password.\n""Type your password below to login.","Login","Quit");
                }
                return 1;
            }
        }



Re: passwords seems to be wrong after registering - Awide - 23.02.2017

By first look this line seems wrong:
Код:
INI_WriteInt(File,"Password");
You write Password into the file, but you didn't tell it what kind of value it should be writing, so it writes nothing! At the login screen you can log in if you leave it blank because your login dialog is checking the password length.

Use this at the registering dialog:
Код:
INI_WriteInt(File,"Password",udb_hash(inputtext));
Use this at the login dialog for checking password:
Код:
if(udb_hash(inputtext) == PlayerInfo[playerid][pPass])
Have you got a saving system? I recommend you to check this guide:
https://sampforum.blast.hk/showthread.php?tid=273088


Re: passwords seems to be wrong after registering - grymtn - 23.02.2017

yeah in first script there was that one actually it hashed my password too so i have 2 accounts yes youre right my second account doesnt have password saved but first one has it saved and hashed still it doesnt quite work still logs in with empty pasword instead of my actual or hashed password fixed code:
Код:
      case DIALOG_REGISTER:
        {
      		if (!response)
            {
                Kick(playerid);
                return 1;
            }
            else if(response)
            {
                if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Register","You have entered an invalid password.\n""Type your password below to register a new account.","Register","Quit");
                new IP[22];
                GetPlayerIp(playerid, IP, sizeof(IP));
                new name[MAX_PLAYER_NAME];
    			GetPlayerName(playerid, name, sizeof(name));
    			
    			PlayerInfo[playerid][pName] = name;
    			PlayerInfo[playerid][pPlate1] = 0;
    			PlayerInfo[playerid][pPlate2] = 0;
    			PlayerInfo[playerid][pPlate3] = 0;
                new INI:File = INI_Open(UserPath(playerid));
                INI_SetTag(File,"data");
                INI_WriteInt(File,"Password",strval(inputtext));
                INI_WriteInt(File,"Cash",0);
                INI_WriteInt(File,"Admin",0);
                INI_WriteInt(File,"Kills",0);
                INI_WriteInt(File,"Deaths",0);
                INI_WriteInt(File,"LSD",0);
                INI_WriteInt(File,"Cocaine",0);
                INI_WriteInt(File,"Marijuana",0);
                INI_WriteInt(File,"Respect",0);
                INI_WriteInt(File,"Cigarettes",0);
                INI_WriteInt(File,"Beer",0);
                INI_WriteString(File, "Ip", IP);
                INI_WriteFloat(File,"Health",0);
                INI_WriteInt(File,"BankAccount",0);
                INI_WriteInt(File,"Datasaved",0);
                INI_WriteInt(File,"Number",0);
                INI_WriteInt(File,"Level",0);
                INI_WriteInt(File,"Crashed",0);
                INI_WriteInt(File,"Phone",0);
                INI_WriteInt(File,"Donator",0);
				INI_WriteInt(File, "Plate1", PlayerInfo[playerid][pPlate1]);
				INI_WriteInt(File, "Plate2", PlayerInfo[playerid][pPlate2]);
				INI_WriteInt(File, "Plate3", PlayerInfo[playerid][pPlate3]);
   				INI_WriteString(File, "Name", PlayerInfo[playerid][pName]);
                INI_Close(File);
				
      			FadeColorForPlayer(playerid,0,0,0,0,0,0,0,255,15,0);
                GivePlayerMoney(playerid, 2500);
                PlayerInfo[playerid][pSkin] = 26;
                PlayerInfo[playerid][pXPos] = 1742.9600;
                PlayerInfo[playerid][pYPos] = -1861.4019;
                PlayerInfo[playerid][pZPos] = 0.2426;
                PlayerInfo[playerid][pLevel] = 1;
                PlayerInfo[playerid][pBankAccount] = 1000;
                SetTimerEx("AgeSetup", 1000, false, "i", playerid);
                new Year, Month, Day;
				getdate(Year, Month, Day);
				PlayerLogged[playerid] = true;
				PlayerInfo[playerid][pYear] = Year;
				PlayerInfo[playerid][pMonth] = Month;
				PlayerInfo[playerid][pDay] = Day;
            }
        }
Код:
        case DIALOG_LOGIN:
        {
      		if(!response)
            {
                Kick(playerid);
                return 1;
            }
            else if(response) 
            {
                if(strval(inputtext) == PlayerInfo[playerid][pPass])
                {
                    INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
                    GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
                    LoadFightingStyle(playerid);
                   	FadeColorForPlayer(playerid,0,0,0,255,0,0,0,0,15,0);
                    SCM(playerid, COLOR_WHITE, "You have successfully logged in.");
                    TogglePlayerSpectating(playerid, false);
                    PlayerLogged[playerid] = true;
                    SetPlayerScore(playerid, PlayerInfo[playerid][pLevel]);
              		new playername[24];
					GetPlayerName(playerid, playername, sizeof(playername));
					
					PlayerInfo[playerid][pName] = playername;
					
					new INI:File = INI_Open(UserPath(playerid));
					INI_SetTag(File,"data");
					INI_WriteString(File, "Name", PlayerInfo[playerid][pName]);
					INI_Close(File);
					
					sInfo[playerid][Misc] = 0;
					sInfo[playerid][Head] = 0;
					sInfo[playerid][Chest] = 0;
					sInfo[playerid][Crotch] = 0;
					sInfo[playerid][LArm] = 0;
					sInfo[playerid][RArm] = 0;
					sInfo[playerid][LLeg] = 0;
					sInfo[playerid][RLeg] = 0;
					
					if(PlayerInfo[playerid][pTutorialDone] == 0) return SetTimerEx("AgeSetup", 1000, false, "i", playerid);
                   	if(PlayerInfo[playerid][pBanned] == 1)
					{
					    SCM(playerid, COLOR_LIGHTRED, "AdmCmd: You have been banned for logging into a banned account.");
    					SetTimerEx("UnsetBan", 500, 0, "i", playerid);
					}
                }
                else
                {
                    ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,"Login","You have entered an incorrect password.\n""Type your password below to login.","Login","Quit");
                }
                return 1;
            }
        }
    }



Re: passwords seems to be wrong after registering - Awide - 24.02.2017

Yes, because the player's password doesn't load in time.
Код:
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
That line is AFTER the password was checked. You need to load the password from the user file BEFORE the player would log in. Can you put that line under OnPlayerConnect?

Something like this
Код:
public OnPlayerConnect(playerid)
{
	if(fexist(UserPath(playerid)))
	{
		INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
  		ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,""COL_WHITE"Login",""COL_WHITE"Type your password below to login.","Login","Quit");
	}
	else
	{
 		ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT,""COL_WHITE"Registering...",""COL_WHITE"Type your password below to register a new account.","Register","Quit");
	}
	return 1;
}