I can't login
#1

I tried to follow this tutorial. Everything was fine, but I can't login
pawn Код:
if(dialogid == login)
    {
        if(!response) return Kick(playerid);
        if(response)
        {
            if(udb_hash(inputtext) == pInfo[playerid][pass])
            {
                INI_ParseFile(Path(playerid),"loaduser_%s",.bExtra = true, .extra = playerid);
                GivePlayerMoney(playerid,pInfo[playerid][money]);
                SetPlayerScore(playerid,pInfo[playerid][score]);
            }
            else
            {
                ShowPlayerDialog(playerid,login,DIALOG_STYLE_INPUT,"Login","You have entered an incorrect password. \nThe name is registered. Enter your password to login to your account.","Login","Quit");
            }
            return 1;
        }
    }
It says "You have entered an incorrect password...".
Reply
#2

You have to parse the file before checking if the passwords match.
pawn Код:
if(udb_hash(inputtext) == pInfo[playerid][pass])
{
    INI_ParseFile(Path(playerid),"loaduser_%s",.bExtra = true, .extra = playerid);
    GivePlayerMoney(playerid,pInfo[playerid][money]);
    SetPlayerScore(playerid,pInfo[playerid][score]);
}
The code is comparing the dialog text to pInfo[playerid][pass] when you haven't even loaded it yet. So when it's not loaded the password equals zero, thus not being able to log you in.
Reply
#3

pass are an integer?
Reply
#4

Quote:
Originally Posted by Viniborn
Посмотреть сообщение
pass are an integer?
Yea, udb_hash specifically returns an integer. Strange, I know.

pawn Код:
/*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;
}
Reply
#5

Quote:
Originally Posted by VincentDunn
Посмотреть сообщение
You have to parse the file before checking if the passwords match.
pawn Код:
if(udb_hash(inputtext) == pInfo[playerid][pass])
{
    INI_ParseFile(Path(playerid),"loaduser_%s",.bExtra = true, .extra = playerid);
    GivePlayerMoney(playerid,pInfo[playerid][money]);
    SetPlayerScore(playerid,pInfo[playerid][score]);
}
The code is comparing the dialog text to pInfo[playerid][pass] when you haven't even loaded it yet. So when it's not loaded the password equals zero, thus not being able to log you in.
How??
Reply
#6

Under OnPlayerConnect...

Check if the userfile exists and then parse it with INI_Parsefile.

This tutorial by Kush is where I learned.

https://sampforum.blast.hk/showthread.php?tid=273088
Reply
#7

Yea I follow that tutorial, but still not working.
Under OnPlayerConnect

pawn Код:
if(fexist(Path(playerid)))
    {
        INI_ParseFile(Path(playerid),"loaduser_%s",.bExtra = true, .extra = playerid);
        ShowPlayerDialog(playerid,login,DIALOG_STYLE_INPUT,"Login","The name is registered. Enter your password to login to your account.","Login","Quit");
    }
Reply
#8

Try Parsing it with INI_ParseFile

before doing this

pawn Код:
if(udb_hash(inputtext) == pInfo[playerid][pass])
Reply
#9

Quote:
Originally Posted by newbienoob
Посмотреть сообщение
Yea I follow that tutorial, but still not working.
Under OnPlayerConnect

pawn Код:
if(fexist(Path(playerid)))
    {
        INI_ParseFile(Path(playerid),"loaduser_%s",.bExtra = true, .extra = playerid);
        ShowPlayerDialog(playerid,login,DIALOG_STYLE_INPUT,"Login","The name is registered. Enter your password to login to your account.","Login","Quit");
    }
I think there is a bug with INI_ParseFile in 0.3e. I tried making a register script, but y_ini hadn't been working on the latest RC's.

EDIT:Try debugging

pawn Код:
INI_ParseFile(Path(playerid),"loaduser_%s",.bExtra = true, .extra = playerid);
// extra code here
printf("[debug] Password: %d", pInfo[playerid][pass]); // print the password to see if it was parsed correctly.
Add that print line, and go try to login. If you look at your server console afterwards and just see
Код:
Password: 0
Then there is either a flaw in your code, or y_ini.
Reply
#10

[debug] Password: 0
(From my server console)
Reply
#11

I suggest consulting ****** with this. Did not work for me either, and I am pretty much 100% sure there is no flaw in the test code.
Reply
#12

Ok
Reply
#13

Damn same problem with INI_Parsefile.
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)