[HELP] Dialog registration system
#1

There is something wrong with this system. When I register an account and disconnect, re-connects and try to login, it just shows me 'Wrong password'.

pawn Код:
enum pInfo
{
    pPassword,
    pCash,
}
new PlayerInfo[MAX_PLAYERS][pInfo];

public OnPlayerConnect(playerid)
{
    new name[MAX_PLAYER_NAME], file[128];
    GetPlayerName(playerid, name, MAX_PLAYER_NAME);
    format(file, sizeof(file), "users/%s.ini", name);
    if(!fexist(file))
    {
        ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "Register", "Please provide your password below.", "Register", "Cancel"); // this is the dialog type
    }
    else
    {
        ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "Login", "Please provide your password below.", "Login", "Cancel");
    }
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    new file[128], name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, MAX_PLAYER_NAME);
    format(file, sizeof(file), "users/%s.ini", name);
    if(dini_Exists(file))
    {
        dini_IntSet(file, "Password", PlayerInfo[playerid][pPassword]);
        dini_IntSet(file, "Cash", PlayerInfo[playerid][pCash]);
    }
    return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == 1)
    {
        new file[128], name[MAX_PLAYER_NAME];
        GetPlayerName(playerid, name, MAX_PLAYER_NAME);
        format(file, sizeof(file), "users/%s.ini", name);
        if(response)
        {
            if(strlen(inputtext))
            {
                dini_Create(file);
                dini_IntSet(file, "Password", num_hash(inputtext));
                dini_IntSet(file, "Cash", PlayerInfo[playerid][pCash]);
                PlayerInfo[playerid][pCash] = dini_Int(file, "Cash");
            }
        }
        else
        {
            Kick(playerid);
        }
    }
    if(dialogid == 2)
    {
        new file[128], name[MAX_PLAYER_NAME], string[128];
        GetPlayerName(playerid, name, MAX_PLAYER_NAME);
        format(string, sizeof(string), "users/%s.ini", name);
        if(response)
        {
            if(strlen(inputtext))
            {
                if(num_hash(inputtext) != dini_Int(file, "Password"))
                {
                    ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "Wrong password!", "Please provide your password below.", "Login", "Cancel");
                }
                else
                {
                    PlayerInfo[playerid][pCash] = dini_Int(file, "Cash");
                }
            }
        }
        else
        {
            Kick(playerid);
        }
    }
    return 1;
}
Thanks in advance.
Reply
#2

On the OnPlayerDisconnect section.
pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
    new file[128], name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, MAX_PLAYER_NAME);
    format(file, sizeof(file), "users/%s.ini", name);
    if(dini_Exists(file))
    {
       // Remove this line!!! dini_IntSet(file, "Password", PlayerInfo[playerid][pPassword]);
        dini_IntSet(file, "Cash", PlayerInfo[playerid][pCash]);
    }
    return 1;
}
What is happening is that d_ini is writing it as 0 when they disconnect. So your password is 0 when you log back in, and lord knows what 0 is in hashed form. Remove the line
pawn Код:
dini_IntSet(file, "Password", PlayerInfo[playerid][pPassword]);
from your OnPlayerDisconnect part and let me know if it works.
Reply
#3

Quote:
Originally Posted by VincentDunn
Посмотреть сообщение
On the OnPlayerDisconnect section.
pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
    new file[128], name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, MAX_PLAYER_NAME);
    format(file, sizeof(file), "users/%s.ini", name);
    if(dini_Exists(file))
    {
       // Remove this line!!! dini_IntSet(file, "Password", PlayerInfo[playerid][pPassword]);
        dini_IntSet(file, "Cash", PlayerInfo[playerid][pCash]);
    }
    return 1;
}
What is happening is that d_ini is writing it as 0 when they disconnect. So your password is 0 when you log back in, and lord knows what 0 is in hashed form. Remove the line
pawn Код:
dini_IntSet(file, "Password", PlayerInfo[playerid][pPassword]);
from your OnPlayerDisconnect part and let me know if it works.
Well now it's as you said, it saves the password but I'm still getting the wrong password thing. :/
Reply
#4

Anyone?
Reply
#5

Never tired to try this?

pawn Код:
if(num_hash(inputtext) == dini_Int(file, "Password"))
Reply
#6

Try this:

pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == 1)
    {
        new file[128], name[MAX_PLAYER_NAME];
        GetPlayerName(playerid, name, MAX_PLAYER_NAME);
        format(file, sizeof(file), "users/%s.ini", name);
        if(response)
        {
            if(strlen(inputtext))
            {
                dini_Create(file);
                dini_IntSet(file, "Password", num_hash(inputtext));
                dini_IntSet(file, "Cash", PlayerInfo[playerid][pCash]);
                PlayerInfo[playerid][pCash] = dini_Int(file, "Cash");
            }
        }
        else
        {
            Kick(playerid);
        }
    }
    if(dialogid == 2)
    {
        new file[128], name[MAX_PLAYER_NAME], string[128];
        GetPlayerName(playerid, name, MAX_PLAYER_NAME);
        format(string, sizeof(string), "users/%s.ini", name);
        if(response)
        {
            if(strlen(inputtext))
            {
                if(num_hash(inputtext) == PlayerInfo[playerid][pPassword])
                {
                    INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
                    GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
                    ShowPlayerDialog(playerid, 999, DIALOG_STYLE_INPUT, "Success Login", "Login", "Cancel");
                }
                else
                {
                    ShowPlayerDialog(playerid, 2, DIALOG_STYLE_PASSWORD,"Invalid Password","Login","Cancel");
                }
            }
        }
        else
        {
            Kick(playerid);
        }
    }
    return 1;
}
Reply
#7

Quote:
Originally Posted by Reklez
Посмотреть сообщение
Never tired to try this?

pawn Код:
if(num_hash(inputtext) == dini_Int(file, "Password"))
Now it allowed me to login with the password I provided but if I try to login on the same user but with a invalid password, is still logs me in and doesn't give me the wrong password dialog.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)