SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 22/09/2019, 03:07 PM   #1
KIRAB
Little Clucker
 
Join Date: Jul 2019
Posts: 3
Reputation: 0
Default LOOKING FOR SOME HELP

CAN ANYONE HELP ME MY SAVING SYSTEM WHICH IS USING Y_INI IS NOT NOT SAVING PASSWORD
Code:
forward LoadUser_data(playerid,name[],value[]);
public LoadUser_data(playerid,name[],value[])
{
    INI_Int("Password",pInfo[playerid][Pass]);
    INI_Int("pAdmin",pInfo[playerid][pAdmLevel]);
    INI_Int("pVip",pInfo[playerid][pVIPLevel]);
    INI_Int("Warn",pInfo[playerid][Warn]);
    INI_Int("Banned",pInfo[playerid][Banned]);
	INI_Int("Jailed",pInfo[playerid][Jailed]);
    INI_Int("Freeze",pInfo[playerid][Freeze]);
    INI_Int("Cash",pInfo[playerid][Cash]);
    INI_Int("Kills",pInfo[playerid][Kills]);
    INI_Int("Deaths",pInfo[playerid][Deaths]);
    return 1;
}
stock GetName(playerid)
{
	new pName[24];
	GetPlayerName(playerid, pName, 24);
	return pName;
}
stock UserPath(playerid)
{
    new string[128];
    format(string,sizeof(string),PATH,GetName(playerid));
    return string;
}

stock udb_hash(buf[]) {
    new length=strlen(buf);
    new s1 = 1;
    new s2 = 0;
    new n;
    for (n=0; n<length; n++)
    {
       s1 = (s1 + buf[n]) % 65521;
       s2 = (s2 + s1)     % 65521;
    }
    return (s2 << 16) + s1;
}
public OnPlayerConnect(playerid)
{
    reported[playerid] = 0;
	AcceptingAdminID[playerid] = -1;
	PlayerThatReported[playerid] = -1;
	SendClientMessage(playerid,COLOR_GREEN,"Welcome to server ");
	if(sLocked == 1) return Kick(playerid);
	if(fexist(UserPath(playerid)))
	{
		//INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
        INI_ParseFile(UserPath(playerid),"loadaccount", .bExtra = true, .extra = playerid, .bPassTag = true);
		ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_INPUT,""white"Login",""white"Type your password below to login.","Login","Quit");
	}
	else
	{
		ShowPlayerDialog(playerid,DIALOG_REGISTER,DIALOG_STYLE_INPUT,""red"Registering...",""white"Type your password below to register a new account.","Register","Quit");
	}
	return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    new INI:File = INI_Open(UserPath(playerid));
    INI_SetTag(File,"data");
	INI_WriteInt(File,"Password",pInfo[playerid][Pass]);
    INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
    INI_WriteInt(File,"pLevel",pInfo[playerid][pAdmLevel]);
    INI_WriteInt(File,"pVIPLevel",pInfo[playerid][pVIPLevel]);
    INI_WriteInt(File,"Warn",pInfo[playerid][Warn]);
    INI_WriteInt(File,"Banned",pInfo[playerid][Banned]);
    INI_WriteInt(File,"Freeze",pInfo[playerid][Freeze]);
    INI_WriteInt(File,"Muted",pInfo[playerid][Muted]);
    INI_WriteInt(File,"Kills",pInfo[playerid][Kills]);
    INI_WriteInt(File,"Deaths",pInfo[playerid][Deaths]);
    INI_Close(File);
    
    JP[playerid] = 0;
    
    if(IsBeingSpeced[playerid] == 1)
    {
        foreach(Player,i)
        {
            if(spectatorid[i] == playerid)
            {
                TogglePlayerSpectating(i,false);
            }
        }
    }
    return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
	switch(dialogid)
	{
	    case DIALOG_REGISTER:
	    {
	        if (!response) return Kick(playerid);
            if(response)
            {
                if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, ""white"Registering...",""red"You have entered an invalid password.\n"white"Type your password below to register a new account.","Register","Quit");
                new INI:File = INI_Open(UserPath(playerid));
                INI_SetTag(File,"data");
                INI_WriteInt(File,"Password",udb_hash(inputtext));
                INI_WriteInt(File,"pLevel",0);
                INI_WriteInt(File,"pVIPLevel",0);
                INI_WriteInt(File,"Warn",0);
                INI_WriteInt(File,"Banned",0);
                INI_WriteInt(File,"Muted",0);
                INI_WriteInt(File,"Freeze",0);
                INI_WriteInt(File,"Cash",0);
                INI_WriteInt(File,"Kills",0);
                INI_WriteInt(File,"Deaths",0);
                INI_Close(File);

                SetSpawnInfo(playerid, 0, 0, 1958.33, 1343.12, 15.36, 269.15, 0, 0, 0, 0, 0, 0);
                SpawnPlayer(playerid);
                ShowPlayerDialog(playerid, DIALOG_SUCCESS_1, DIALOG_STYLE_MSGBOX,""white"Success!",""green"Great! Your Y_INI system works perfectly. Relog to save your stats!","Ok","");
            }
	    }
	    case DIALOG_LOGIN:
	    {
	    	if ( !response ) return Kick ( playerid );
            if( response )
            {
                if(udb_hash(inputtext) == pInfo[playerid][Pass])
                {
                    INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
					if(pInfo[playerid][Banned] >= 1) return Kick(playerid);
					if(pInfo[playerid][Jailed] == 1) 
					{
						SetPlayerPos(playerid, 264.8763,81.9862,1001.0390);
						SetPlayerInterior(playerid, 6);
					}
					if(pInfo[playerid][Freeze] == 1)
					{
						TogglePlayerControllable(playerid,false);
					}
					GivePlayerMoney(playerid, pInfo[playerid][Cash]);
                    ShowPlayerDialog(playerid, DIALOG_SUCCESS_2, DIALOG_STYLE_MSGBOX,""white"Success!",""green"You have successfully logged in!","Ok","");
                }
                else
                {
                    ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,""white"Login",""red"You have entered an incorrect password.\n"white"Type your password below to login.","Login","Quit");
                }
                return 1;
            }
		}

Last edited by KIRAB; 22/09/2019 at 03:10 PM. Reason: MISSED SOME CODE
KIRAB is offline   Reply With Quote
Old 23/09/2019, 11:08 AM   #2
Jonny
Huge Clucker
 
Jonny's Avatar
 
Join Date: Nov 2009
Location: Italy
Posts: 280
Reputation: 38
Default Re: LOOKING FOR SOME HELP

You surely load your password in "loadaccount", why reloading it in LoadUser?
__________________
Jonny is offline   Reply With Quote
Old 23/09/2019, 12:04 PM   #3
Plastikmensch
Huge Clucker
 
Join Date: Aug 2016
Posts: 272
Reputation: 27
Default Re: LOOKING FOR SOME HELP

I just guess, when you connect to the server, register your account, disconnect and look at the file, there is "Password 0"?
When a player registers, you save the password, but you don't set pInfo[playerid][Pass].
In OnPlayerDisconnect you use pInfo[playerid][Pass] which is unset if a player just registered, so 0.
If you look at the file while still connected, the password or more precise the bad hash should be there, the moment you disconnect, it's 0.
Please don't use udb_hash if you actually want to run the server as public server.
Use a plugin like bcrypt to hash passwords.
Plastikmensch 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



All times are GMT. The time now is 02:15 AM.


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