SA-MP Forums Archive
Password saves "0" - 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: Password saves "0" (/showthread.php?tid=375524)

Pages: 1 2


Password saves "0" [Added the codes] - Guitar - 07.09.2012

Hey guys,

My saving system (Using Y_INI and tutorial from Kush), the problem started lately, it wasn't there .. I don't know how to fix it. The password saves as 0 if a player disconnects/quits the server. I need somebody to help me over TeamViewer.

This is when the player registers:

pawn Code:
switch( dialogid )
    {
        case DIALOG_REGISTER:
        {
            if (!response) return Kick(playerid);
            if(response)
            {
                if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, ""COL_WHITE"Registering...",""COL_RED"You have entered an invalid password.\n"COL_WHITE"Type your password below to register a new account.","Register","Quit");
                new INI:File = INI_Open(UserPath(playerid));
                INI_SetTag(File,"PlayerData");
                INI_WriteInt(File,"Password",udb_hash(inputtext));
                INI_WriteInt(File,"Cash",0);
                INI_WriteInt(File,"Admin",-1);
                INI_WriteInt(File,"Kills",0);
                INI_WriteInt(File,"Deaths",0);
                INI_WriteInt(File,"Zombie",0);
                INI_WriteInt(File,"Score",1);
                INI_WriteInt(File,"Team",-1);
                INI_WriteInt(File,"Registered",1);
                INI_WriteInt(File,"Logged",1);
               
                PlayerInfo[playerid][pTeam] = -1;
                PlayerInfo[playerid][pAdmin] = -1;
                //PlayerInfo[playerid][pPass] = (inputtext);
               
                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,""COL_WHITE"Success!",""COL_GREEN"Great! Your Y_INI system works perfectly. Relog to save your stats!","Ok","");
            }
        }
This is when the player quits(The problem happens when the player quits/leaves the server:

pawn Code:
public OnPlayerDisconnect(playerid, reason)
{
    PlayerInfo[playerid][pLogged] = 0;
    new INI:File = INI_Open(UserPath(playerid));
    INI_SetTag(File,"PlayerData");
    INI_WriteInt(File,"Password",PlayerInfo[playerid][pPass]);
    INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
    INI_WriteInt(File,"Admin",PlayerInfo[playerid][pAdmin]);
    INI_WriteInt(File,"Kills",PlayerInfo[playerid][pKills]);
    INI_WriteInt(File,"Deaths",PlayerInfo[playerid][pDeaths]);
    INI_WriteInt(File,"Starter",PlayerInfo[playerid][pStarter]);
    INI_WriteInt(File,"Zombie",PlayerInfo[playerid][pZombie]);
    INI_WriteInt(File,"Score",GetPlayerScore(playerid));
    INI_WriteInt(File,"Team",PlayerInfo[playerid][pTeam]);
    INI_WriteInt(File,"Registered",PlayerInfo[playerid][pReg]);
    INI_WriteInt(File,"Logged",PlayerInfo[playerid][pLogged]);
    INI_Close(File);
    return 1;
}
Another "SavePlayerStats" for for example commands like /setlevel etc.. to save the level.

pawn Code:
forward SavePlayerStats(playerid);
public SavePlayerStats(playerid)
{
    new INI:File = INI_Open(UserPath(playerid));
    INI_SetTag(File,"PlayerData");
    INI_WriteInt(File,"Password",PlayerInfo[playerid][pPass]);
    INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
    INI_WriteInt(File,"Admin",PlayerInfo[playerid][pAdmin]);
    INI_WriteInt(File,"Kills",PlayerInfo[playerid][pKills]);
    INI_WriteInt(File,"Deaths",PlayerInfo[playerid][pDeaths]);
    INI_WriteInt(File,"Starter",PlayerInfo[playerid][pStarter]);
    INI_WriteInt(File,"Zombie",PlayerInfo[playerid][pZombie]);
    INI_WriteInt(File,"Score",GetPlayerScore(playerid));
    INI_WriteInt(File,"Team",PlayerInfo[playerid][pTeam]);
    INI_WriteInt(File,"Registered",PlayerInfo[playerid][pReg]);
    INI_WriteInt(File,"Logged",PlayerInfo[playerid][pLogged]);
    INI_Close(File);
    print("\n----------------------------------");
    print(" Players' accounts saved! On SavePlayerStats");
    print("----------------------------------\n");
    return 1;
}



Re: Password saves "0" - doreto - 07.09.2012

Show as the code or leave this to spiderman

<removed pointless meme>


Re: Password saves "0" - HuSs3n - 07.09.2012

probably because you save it as an INT not as a STRING


Re: Password saves "0" - Guitar - 07.09.2012

I wanted to show the code, but .. I didn't know which one because it works just as Kush's so, the problem is being caused by something else :S -


Re: Password saves "0" - Guitar - 07.09.2012

(( OMG Sorry for doulbe-posting, I totally didn't notice it .. ))


Re: Password saves "0" - HuSs3n - 07.09.2012

pawn Code:
INI_WriteInt(File,"Password",...);
should be
pawn Code:
INI_WriteString(File,"Password",...);



Re: Password saves "0" - Guitar - 07.09.2012

Quote:
Originally Posted by HuSs3n
View Post
pawn Code:
INI_WriteInt(File,"Password",udb_hash(inputtext));
should be
pawn Code:
INI_WriteString(File,"Password",udb_hash(inputtext));
This is not my problem, it writes in the file strings and numbers


Re: Password saves "0" - HuSs3n - 07.09.2012

what do you mean
you cant use INI_WriteInt for writing strings
thats why it always save 0


Re: Password saves "0" - Guitar - 07.09.2012

But doing this: INI_WriteString(File,"Password",udb_hash(inputtext ));

Will give me this:

pawn Code:
C:\Users\3hab\Desktop\BlackEvo 4\samp03e_svr_R2_win32\gamemodes\funland.pwn(1232) : error 035: argument type mismatch (argument 3)
Pawn compiler 3.2.3664          Copyright (c) 1997-2006, ITB CompuPhase


1 Error.



Re: Password saves "0" - Cjgogo - 07.09.2012

DO NOT USE udb_Hash, it's useless, and it sucks, honestly.It's buggy, and sometimes you won't be able to log in.Use Whirlpool plugin by ****** to hash strings:https://sampforum.blast.hk/showthread.php?tid=65290.


Re: Password saves "0" - JaKe Elite - 07.09.2012

Huss3n, udb_hash is a string not a integer, so he is using correct INI_WriteInt.
anyway, udb_hash is useless like Cjgogo said use whirlpool.
It hash the password in string. Try printing players password on server console (samp-server.exe) when Player's Data is loaded.


Re: Password saves "0" - Guitar - 07.09.2012

Alrighty guys, thanks, but how can I use this Whirlpool hashing way? I tried but failed .


Re: Password saves "0" - RedFusion - 07.09.2012

You dont have to write everything in the player's file upon disconnect, Password for example, Save it only upon player registration. OnPlayerDisconnect is known for bugs when it comes to writing strings


Re: Password saves "0" - sniperwars - 07.09.2012

Why don't you use udb hashing ? That can be used with Y_Ini you know.


Re: Password saves "0" - Guitar - 08.09.2012

@RedFusion,

Sure, but how can I make them save in a better way?

@Sniperwars, I would love to learn how to use Whirlpool

UPDATE: After removing the " INI_WriteInt(File,"Password",PlayerInfo[playerid][pPass]); " from the SavePlayerStats AND OnPlayerDisconnect and putting the password to save in registration like this:

pawn Code:
INI_WriteInt(File,"Password",PlayerInfo[playerid][pPass]);
                INI_Close(File);
                print("(File) has been closed and password is saved.");
Password saves, but when I try to reconnect then put the password, it says that the password is wrong.


UPDATE:

I have put the Whirlpool plugin and did this:

pawn Code:
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, ""COL_WHITE"Registering...",""COL_RED"You have entered an invalid password.\n"COL_WHITE"Type your password below to register a new account.","Register","Quit");
                new INI:File = INI_Open(UserPath(playerid));
                INI_SetTag(File,"PlayerData");
                //INI_WriteString(File,"Password",udb_hash(inputtext));
                new buf[145];
                WP_Hash(buf, sizeof(buf), inputtext);
                //if(strcmp(Password, buf) == true)
               
                INI_WriteInt(File,"Password",WP_Hash(buf, sizeof(buf), inputtext));
                INI_WriteInt(File,"Cash",0);
                INI_WriteInt(File,"Admin",-1);
                INI_WriteInt(File,"Kills",0);
                INI_WriteInt(File,"Deaths",0);
                INI_WriteInt(File,"Zombie",0);
                INI_WriteInt(File,"Score",1);
                INI_WriteInt(File,"Team",-1);
                INI_WriteInt(File,"Registered",1);
                INI_WriteInt(File,"Logged",1);
               
                PlayerInfo[playerid][pTeam] = -1;
                PlayerInfo[playerid][pAdmin] = -1;
               
               
               
                INI_Close(File);
               
                print("(File) has been opened and Password was saved. ");
                INI_WriteInt(File,"Password",PlayerInfo[playerid][pPass]);
                INI_Close(File);
                print("(File) has been closed and password is saved.");

                ShowPlayerDialog(playerid, DIALOG_SUCCESS_1, DIALOG_STYLE_MSGBOX,""COL_WHITE"Success!",""COL_GREEN"Great! Your Y_INI system works perfectly. Relog to save your stats!","Ok","");
            }
        }

        case DIALOG_LOGIN:
        {
            if ( !response ) return Kick ( playerid );
            if( response )
            {
                new buf[145];
                if(WP_Hash(buf, sizeof(buf), inputtext) == PlayerInfo[playerid][pPass])
                {
                    INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
                    GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
                    ShowPlayerDialog(playerid, DIALOG_SUCCESS_2, DIALOG_STYLE_MSGBOX,""COL_WHITE"Success!",""COL_GREEN"You have successfully logged in!","Ok","");
                }
                else
                {
                    ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,""COL_WHITE"Login",""COL_RED"You have entered an incorrect password.\n"COL_WHITE"Type your password below to login.","Login","Quit");
                }
                return 1;
            }
        }
    }
    return 1;
}
But the password again saves as 0.


Re: Password saves "0" - Guitar - 08.09.2012

Bump


Re: Password saves "0" - JaKe Elite - 08.09.2012

You are fail.
Buf is not a integer.
Its a string.
Why you hashing the password when its already hash?

pawn Code:
INI_WriteString(File,"Password",buf);



Re: Password saves "0" - Guitar - 08.09.2012

Quote:
Originally Posted by Romel
View Post
You are fail.
Buf is not a integer.
Its a string.
Why you hashing the password when its already hash?

pawn Code:
INI_WriteString(File,"Password",buf);
Works, but I have another problem, now when a player logs in, he can just type any password and log in, it seems my logging-in script doesn't read the password here it is

pawn Code:
case DIALOG_LOGIN:
        {
            if ( !response ) return Kick ( playerid );
            if( response )
            {
                new buf[145];
                if(WP_Hash(buf, sizeof(buf), inputtext) == PlayerInfo[playerid][pPass])
                {
                    INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
                    GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
                    ShowPlayerDialog(playerid, DIALOG_SUCCESS_2, DIALOG_STYLE_MSGBOX,""COL_WHITE"Success!",""COL_GREEN"You have successfully logged in!","Ok","");
                }
                else
                {
                    ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,""COL_WHITE"Login",""COL_RED"You have entered an incorrect password.\n"COL_WHITE"Type your password below to login.","Login","Quit");
                }
                return 1;
            }
        }
    }



Re: Password saves "0" - Kush - 08.09.2012

@Cjgogo - How in the world is it buggy or useless? The only thing I'll agree with you on is that it sucks. It's plain horrible and I used it as a cheap method in my tutorial. Anyway, it'd be best to use Whirlpool.

@Guitar - Bro, use WriteInt instead of WriteString. The password must be saved as an integer.


Re: Password saves "0" - JaKe Elite - 08.09.2012

@Kush, he is now using Whirlpool. Whirlpool hash password on string not on integer.

@Guitar, LoadUser_Data. Not sure since i use newbienoob tutorial. Which works fine for me.

he says on his tutorial:

try changing

loadaccount_%s

to

loadaccount_user

when you can login with any password.

Since yours is different i'm not sure.