SA-MP Forums Archive
Problem with strcmp - 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: Problem with strcmp (/showthread.php?tid=515634)



Problem with strcmp - verlaj - 27.05.2014

i am using whirlpool to hass passes and everything is fine(even it saves the hassed pass in .ini) but now problem comes with login stuff, even if players input incorrect pass, he still logs in but he dosent get the stats, here is what i am using.

update : he gets the stats if he insert correct pass

pawn Код:
enum pInfo
{
    Pass[129]
}
new PlayerInfo[MAX_PLAYERS][pInfo];




public loadaccount_user(playerid, name[], value[])
{
    INI_String("Password", PlayerInfo[playerid][Pass],129);
    return 1;
}

//on dialog response

if(dialogid == DIALOG_LOGIN)
        {
            if(!response) return Kick(playerid); //
            if(response) //
            {//
                new hashpass[129]; //
                WP_Hash(hashpass,sizeof(hashpass),inputtext);
                if(!strcmp(hashpass,PlayerInfo[playerid][Pass]))
                {//then
                    INI_ParseFile(UserPath(playerid),"loadaccount_%s",.bExtra = true, .extra = playerid);
                    SetPlayerScore(playerid,PlayerInfo[playerid][Score]);//
                    GivePlayerMoney(playerid,PlayerInfo[playerid][Cash]);
                    SendClientMessage(playerid,-1,"Welcome back! You have successfully logged in");//
                 
                }
                else //
                {//
                    ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_PASSWORD,"Login","Welcome back. This account is registered. \nInsert your password to login to your account.\nIncorrect password!","Login","Quit");//We will tell to them that they've entered an incorrect password
                    return 1;
                }
            }
            return 1;
        }



Re: Problem with strcmp - Rittik - 27.05.2014

Use this hashing stock function.

Код:
/*Credits to Dracoblue*/
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;
}
for login do this.
Код:
if(udb_hash(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","");
                }



Re: Problem with strcmp - verlaj - 27.05.2014

well mate there is a slight error with this.

if(udb_hash(inputtext) == PlayerInfo[playerid][pPass])


Re: Problem with strcmp - Rittik - 27.05.2014

No errors mate I have tried it myself.


Re: Problem with strcmp - Rittik - 27.05.2014

Try it.
Код:
if(dialogid == DIALOG_LOGIN)
        {
            if(!response) return Kick(playerid); //
            if(response) //
            {//
                new hashpass[129]; //
                WP_Hash(hashpass,sizeof(hashpass),inputtext); 
                if(hashpass==PlayerInfo[playerid][Pass]) //try out this
                {//then
                    INI_ParseFile(UserPath(playerid),"loadaccount_%s",.bExtra = true, .extra = playerid);
                    SetPlayerScore(playerid,PlayerInfo[playerid][Score]);//
                    GivePlayerMoney(playerid,PlayerInfo[playerid][Cash]);
                    SendClientMessage(playerid,-1,"Welcome back! You have successfully logged in");//
                 
                }
                else //
                {//
                    ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_PASSWORD,"Login","Welcome back. This account is registered. \nInsert your password to login to your account.\nIncorrect password!","Login","Quit");//We will tell to them that they've entered an incorrect password
                    return 1;
                }
            }
            return 1;
        }



Re: Problem with strcmp - verlaj - 27.05.2014

if(hashpass==PlayerInfo[playerid][Pass])

this code wont work.


Re: Problem with strcmp - iZN - 27.05.2014

udb hash is a ridiculous hash, you should NOT use that hash because it's barely secure. You should consider using Whirlpool like you were doing before, the above poster have no idea about secure hash so don't follow him. Can you show some more of your code related to loading of accounts?


Re: Problem with strcmp - Jack_Leslie - 27.05.2014

Try changing:
pawn Код:
if(!strcmp(hashpass,PlayerInfo[playerid][Pass]))

To:
pawn Код:
if(strcmp(hashpass, PlayerInfo[playerid][Pass], true) == 0)



Re: Problem with strcmp - verlaj - 27.05.2014

fixed needed to change

loadaccount_%s
to
loadaccount_user