y_ini login system help
#1

Hello everyone.
I am currently working on a login/register system using y_ini and whirlpool.
I more or less made the system already. My problem is though, that when I log in, it does not recognize my password, and gives me the "Incorrect password" dialog that I made.
My code looks like this...
On top of the script:
pawn Код:
enum pInfo
{
    pPassword[129]
}

new PlayerInfo[MAX_PLAYERS][pInfo];

forward LoadUser_data(playerid,name[],value[]);
public LoadUser_data(playerid,name[],value[])
{
    INI_String("password", PlayerInfo[playerid][pPassword], 129);
    return 1;
}

stock UserPath(playerid)
{
    new string[128],playername[MAX_PLAYER_NAME];
    GetPlayerName(playerid,playername,sizeof(playername));
    format(string,sizeof(string),"Users/%s.ini",playername);
    return string;
}
OnPlayerConnect:
pawn Код:
public OnPlayerConnect(playerid)
{
    new name[MAX_PLAYER_NAME];
    if(!fexist(UserPath(playerid)))
    {
        new string[367 + MAX_PLAYER_NAME];
        GetPlayerName(playerid, name, sizeof(name));
        format(string, sizeof(string), "-MSG- The username '%s' is not registered. Please enter a Password to Register",name);
        SendClientMessage(playerid, COLOR_YELLOW, string);
        format(string, sizeof(string), "{FFFF00}Requested username: {FFFFFF}%s\nThis username is: {009900}Available\n\n{AF0000}We suggest that you don't register\nwith an RP name (Firstname_Lastname)\nbecause you can manage multiple\ncharacters from one account.\nThe name you register now will not\nbe your in-game name.\n\n{FFFFFF}By registering,\nyou agree to our terms of use.\n\n{FFFF00}Enter a Password to register",name);
        ShowPlayerDialog(playerid, MENU_REGISTER, DIALOG_STYLE_PASSWORD, "Hopes Hills RP Account", string, "Register", "Quit");
    }
    else
    {
        INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
        new string[80 + MAX_PLAYER_NAME];
        GetPlayerName(playerid, name, sizeof(name));
        format(string, sizeof(string), "-MSG- The username '%s' is already registered. Please log in with your Password",name);
        SendClientMessage(playerid, COLOR_YELLOW, string);
        SendClientMessage(playerid, COLOR_GREY, "-MSG- Not your account? Then relog with another name");
        format(string, sizeof(string), "{FFFF00}Your username: {FFFFFF}%s\n\nEnter your Password to log in",name);
        ShowPlayerDialog(playerid, MENU_LOGIN, DIALOG_STYLE_PASSWORD, "Hopes Hills RP Account", string, "Login", "Quit");
    }
    return 1;
}
OnDialogResponse:
pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch ( dialogid )
    {
        case MENU_REGISTER:
        {
            if (!response)
            {
                SendClientMessage(playerid, COLOR_DARKRED, "-MSG- You must register in order to play on this server");
                Kick(playerid);
            }
            else
            {
                if(strlen(inputtext) > 20 || strlen(inputtext) < 5)
                {
                    new string[170 + MAX_PLAYER_NAME], name[MAX_PLAYER_NAME];
                    format(string, sizeof(string), "{FFFF00}Requested username: {FFFFFF}%s\n\n{AF0000}Password must be 5-20 characters\n\n{FFFFFF}By registering,\nyou agree to our terms of use.\n\n{FFFF00}Enter a Password to register",name);
                    ShowPlayerDialog(playerid, MENU_REGISTER, DIALOG_STYLE_PASSWORD, "Hopes Hills RP Account", string, "Register", "Quit");
                }
                else
                {
                    new buf[129];
                    WP_Hash(buf, sizeof(buf), inputtext);
                    new INI:iniFile = INI_Open(UserPath(playerid));
                    INI_SetTag(iniFile, "GENERAL");
                    INI_WriteString(iniFile, "password", buf);
                    INI_WriteInt(iniFile, "admin_level", 0);
                    INI_WriteInt(iniFile, "permanent_banned", 0);
                    INI_Close(iniFile);
                }
            }
        }
        case MENU_LOGIN:
        {
            if (!response)
            {
                SendClientMessage(playerid, COLOR_DARKRED, "-MSG- You must log in in order to play on this server");
                Kick(playerid);
            }
            else
            {
                new buf[129];
                WP_Hash(buf, sizeof(buf), inputtext);
                if(!strcmp(buf, PlayerInfo[playerid][pPassword], false))
                {
                    new string[100 + MAX_PLAYER_NAME], name[MAX_PLAYER_NAME];
                    GetPlayerName(playerid, name, sizeof(name));
                    format(string, sizeof(string), "{FFFF00}Your username: {FFFFFF}%s\n\n{AF0000}Incorrect password!\n\n{FFFF00}Enter your Password to log in",name);
                    ShowPlayerDialog(playerid, MENU_LOGIN, DIALOG_STYLE_PASSWORD, "Hopes Hills RP Account", string, "Login", "Quit");
                }
                else
                {
                    SendClientMessage(playerid, COLOR_GREEN, "-MSG- Welcome back!");
                }
            }
        }
    }
    return 1;
}
Hope someone out there can spot my mistake, because I can't. Thanks in advance.
Reply
#2

Try looking and reading through this tutorial https://sampforum.blast.hk/showthread.php?tid=273088. It helped me a while ago. Hope this helps
Reply
#3

Quote:
Originally Posted by Blademaster680
Посмотреть сообщение
Try looking and reading through this tutorial https://sampforum.blast.hk/showthread.php?tid=273088. It helped me a while ago. Hope this helps
Yea. I have already looked through some, and mine looks the same. But I can still not log in :I
Reply
#4

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

forward LoadUser_data(playerid,name[],value[]);
public LoadUser_data(playerid,name[],value[])
{
    INI_String("password", PlayerInfo[playerid][pPassword], 129);
    return 1;
}

stock UserPath(playerid)
{
    new string[35], playername[MAX_PLAYER_NAME];
    GetPlayerName(playerid,playername,sizeof(playername));
    format(string,sizeof(string),"Users/%s.ini",playername);
    return string;
}

public OnPlayerConnect(playerid)
{
    new name[MAX_PLAYER_NAME];
    if(!fexist(UserPath(playerid)))
    {
        new string[367 + MAX_PLAYER_NAME];
        GetPlayerName(playerid, name, sizeof(name));
        format(string, sizeof(string), "-MSG- The username '%s' is not registered. Please enter a Password to Register",name);
        SendClientMessage(playerid, COLOR_YELLOW, string);
        format(string, sizeof(string), "{FFFF00}Requested username: {FFFFFF}%s\nThis username is: {009900}Available\n\n{AF0000}We suggest that you don't register\nwith an RP name (Firstname_Lastname)\nbecause you can manage multiple\ncharacters from one account.\nThe name you register now will not\nbe your in-game name.\n\n{FFFFFF}By registering,\nyou agree to our terms of use.\n\n{FFFF00}Enter a Password to register",name);
        ShowPlayerDialog(playerid, MENU_REGISTER, DIALOG_STYLE_PASSWORD, "Hopes Hills RP Account", string, "Register", "Quit");
    }
    else
    {
        INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
        new string[80 + MAX_PLAYER_NAME];
        GetPlayerName(playerid, name, sizeof(name));
        format(string, sizeof(string), "-MSG- The username '%s' is already registered. Please log in with your Password",name);
        SendClientMessage(playerid, COLOR_YELLOW, string);
        SendClientMessage(playerid, COLOR_GREY, "-MSG- Not your account? Then relog with another name");
        format(string, sizeof(string), "{FFFF00}Your username: {FFFFFF}%s\n\nEnter your Password to log in",name);
        ShowPlayerDialog(playerid, MENU_LOGIN, DIALOG_STYLE_PASSWORD, "Hopes Hills RP Account", string, "Login", "Quit");
    }
    return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch ( dialogid )
    {
        case MENU_REGISTER:
        {
            if (!response)
            {
                SendClientMessage(playerid, COLOR_DARKRED, "-MSG- You must register in order to play on this server");
                return Kick(playerid);
            }
            else
            {
                if(strlen(inputtext) > 20 || strlen(inputtext) < 5)
                {
                    new string[170 + MAX_PLAYER_NAME], name[MAX_PLAYER_NAME];
                    GetPlayerName(playerid, name, sizeof(name));
                    format(string, sizeof(string), "{FFFF00}Requested username: {FFFFFF}%s\n\n{AF0000}Password must be 5-20 characters\n\n{FFFFFF}By registering,\nyou agree to our terms of use.\n\n{FFFF00}Enter a Password to register",name);
                    return ShowPlayerDialog(playerid, MENU_REGISTER, DIALOG_STYLE_PASSWORD, "Hopes Hills RP Account", string, "Register", "Quit");
                }
                else
                {
                    new buf[129];
                    WP_Hash(buf, sizeof(buf), inputtext);
                    new INI:iniFile = INI_Open(UserPath(playerid));
                    INI_SetTag(iniFile, "data");
                    INI_WriteString(iniFile, "password", buf);
                    INI_WriteInt(iniFile, "admin_level", 0);
                    INI_WriteInt(iniFile, "permanent_banned", 0);
                    INI_Close(iniFile);
                }
            }
            return 1;
        }
        case MENU_LOGIN:
        {
            if (!response)
            {
                SendClientMessage(playerid, COLOR_DARKRED, "-MSG- You must log in in order to play on this server");
                return Kick(playerid);
            }
            else
            {
                new buf[129];
                WP_Hash(buf, sizeof(buf), inputtext);
                if(strcmp(buf, PlayerInfo[playerid][pPassword], false) != 0)
                {
                    new string[100 + MAX_PLAYER_NAME], name[MAX_PLAYER_NAME];
                    GetPlayerName(playerid, name, sizeof(name));
                    format(string, sizeof(string), "{FFFF00}Your username: {FFFFFF}%s\n\n{AF0000}Incorrect password!\n\n{FFFF00}Enter your Password to log in",name);
                    return ShowPlayerDialog(playerid, MENU_LOGIN, DIALOG_STYLE_PASSWORD, "Hopes Hills RP Account", string, "Login", "Quit");
                }
                else SendClientMessage(playerid, COLOR_GREEN, "-MSG- Welcome back!");
            }
            return 1;
        }
    }
    return 0;
}
Basically, you had 'if(!strcmp(buf, inputtext, false))' which means 'both strings are equal and match each other, or... correct password', where you should of had 'if(strcmp(buf, inputtext, false) != 0)' which means 'both strings do not match each other, or... incorrect password'. Read here: https://sampwiki.blast.hk/wiki/strcmp

I also tidied up your code just slightly, but not by much because I'm in a rush.
Reply
#5

Quote:
Originally Posted by BenzoAMG
Посмотреть сообщение
pawn Код:
enum pInfo
{
    pPassword[129]
}
new PlayerInfo[MAX_PLAYERS][pInfo];

forward LoadUser_data(playerid,name[],value[]);
public LoadUser_data(playerid,name[],value[])
{
    INI_String("password", PlayerInfo[playerid][pPassword], 129);
    return 1;
}

stock UserPath(playerid)
{
    new string[35], playername[MAX_PLAYER_NAME];
    GetPlayerName(playerid,playername,sizeof(playername));
    format(string,sizeof(string),"Users/%s.ini",playername);
    return string;
}

public OnPlayerConnect(playerid)
{
    new name[MAX_PLAYER_NAME];
    if(!fexist(UserPath(playerid)))
    {
        new string[367 + MAX_PLAYER_NAME];
        GetPlayerName(playerid, name, sizeof(name));
        format(string, sizeof(string), "-MSG- The username '%s' is not registered. Please enter a Password to Register",name);
        SendClientMessage(playerid, COLOR_YELLOW, string);
        format(string, sizeof(string), "{FFFF00}Requested username: {FFFFFF}%s\nThis username is: {009900}Available\n\n{AF0000}We suggest that you don't register\nwith an RP name (Firstname_Lastname)\nbecause you can manage multiple\ncharacters from one account.\nThe name you register now will not\nbe your in-game name.\n\n{FFFFFF}By registering,\nyou agree to our terms of use.\n\n{FFFF00}Enter a Password to register",name);
        ShowPlayerDialog(playerid, MENU_REGISTER, DIALOG_STYLE_PASSWORD, "Hopes Hills RP Account", string, "Register", "Quit");
    }
    else
    {
        INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
        new string[80 + MAX_PLAYER_NAME];
        GetPlayerName(playerid, name, sizeof(name));
        format(string, sizeof(string), "-MSG- The username '%s' is already registered. Please log in with your Password",name);
        SendClientMessage(playerid, COLOR_YELLOW, string);
        SendClientMessage(playerid, COLOR_GREY, "-MSG- Not your account? Then relog with another name");
        format(string, sizeof(string), "{FFFF00}Your username: {FFFFFF}%s\n\nEnter your Password to log in",name);
        ShowPlayerDialog(playerid, MENU_LOGIN, DIALOG_STYLE_PASSWORD, "Hopes Hills RP Account", string, "Login", "Quit");
    }
    return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch ( dialogid )
    {
        case MENU_REGISTER:
        {
            if (!response)
            {
                SendClientMessage(playerid, COLOR_DARKRED, "-MSG- You must register in order to play on this server");
                return Kick(playerid);
            }
            else
            {
                if(strlen(inputtext) > 20 || strlen(inputtext) < 5)
                {
                    new string[170 + MAX_PLAYER_NAME], name[MAX_PLAYER_NAME];
                    GetPlayerName(playerid, name, sizeof(name));
                    format(string, sizeof(string), "{FFFF00}Requested username: {FFFFFF}%s\n\n{AF0000}Password must be 5-20 characters\n\n{FFFFFF}By registering,\nyou agree to our terms of use.\n\n{FFFF00}Enter a Password to register",name);
                    return ShowPlayerDialog(playerid, MENU_REGISTER, DIALOG_STYLE_PASSWORD, "Hopes Hills RP Account", string, "Register", "Quit");
                }
                else
                {
                    new buf[129];
                    WP_Hash(buf, sizeof(buf), inputtext);
                    new INI:iniFile = INI_Open(UserPath(playerid));
                    INI_SetTag(iniFile, "data");
                    INI_WriteString(iniFile, "password", buf);
                    INI_WriteInt(iniFile, "admin_level", 0);
                    INI_WriteInt(iniFile, "permanent_banned", 0);
                    INI_Close(iniFile);
                }
            }
            return 1;
        }
        case MENU_LOGIN:
        {
            if (!response)
            {
                SendClientMessage(playerid, COLOR_DARKRED, "-MSG- You must log in in order to play on this server");
                return Kick(playerid);
            }
            else
            {
                new buf[129];
                WP_Hash(buf, sizeof(buf), inputtext);
                if(strcmp(buf, PlayerInfo[playerid][pPassword], false) != 0)
                {
                    new string[100 + MAX_PLAYER_NAME], name[MAX_PLAYER_NAME];
                    GetPlayerName(playerid, name, sizeof(name));
                    format(string, sizeof(string), "{FFFF00}Your username: {FFFFFF}%s\n\n{AF0000}Incorrect password!\n\n{FFFF00}Enter your Password to log in",name);
                    return ShowPlayerDialog(playerid, MENU_LOGIN, DIALOG_STYLE_PASSWORD, "Hopes Hills RP Account", string, "Login", "Quit");
                }
                else SendClientMessage(playerid, COLOR_GREEN, "-MSG- Welcome back!");
            }
            return 1;
        }
    }
    return 0;
}
Basically, you had 'if(!strcmp(buf, inputtext, false))' which means 'both strings are equal and match each other, or... correct password', where you should of had 'if(strcmp(buf, inputtext, false) != 0)' which means 'both strings do not match each other, or... incorrect password'. Read here: https://sampwiki.blast.hk/wiki/strcmp

I also tidied up your code just slightly, but not by much because I'm in a rush.
Thanks for your help, but it is not working. I can log in no matter what password I type. I have been reading through multiple tutorials and done the same as them. I am about to give up...
Reply
#6

Oh, did you change this in your 'Register' dialog? I forgot to mention that I changed more than the 'login' part of it.
pawn Код:
new INI:iniFile = INI_Open(UserPath(playerid));
                    INI_SetTag(iniFile, "data");
                    INI_WriteString(iniFile, "password", buf);
                    INI_WriteInt(iniFile, "admin_level", 0);
                    INI_WriteInt(iniFile, "permanent_banned", 0);
                    INI_Close(iniFile);
The whole code that I gave is what you need to replace it with.
Reply
#7

Quote:
Originally Posted by BenzoAMG
Посмотреть сообщение
Oh, did you change this in your 'Register' dialog? I forgot to mention that I changed more than the 'login' part of it.
pawn Код:
new INI:iniFile = INI_Open(UserPath(playerid));
                    INI_SetTag(iniFile, "data");
                    INI_WriteString(iniFile, "password", buf);
                    INI_WriteInt(iniFile, "admin_level", 0);
                    INI_WriteInt(iniFile, "permanent_banned", 0);
                    INI_Close(iniFile);
The whole code that I gave is what you need to replace it with.
OMG thank you!!! It was just that little "data" in stead of "GENERAL" as I made. What a silly little mistake
Reply
#8

For further explanation, 'LoadUser_%s', whatever you have after the '_' is the tag that you want to load. Another fix could of been to change 'LoadUser_data' to 'LoadUser_GENERAL'. A lot of examples on the SA-MP forums use the 'data' tag, so it would be easier to do it that way.

And you're welcome
Reply
#9

Quote:
Originally Posted by BenzoAMG
Посмотреть сообщение
For further explanation, 'LoadUser_%s', whatever you have after the '_' is the tag that you want to load. Another fix could of been to change 'LoadUser_data' to 'LoadUser_GENERAL'. A lot of examples on the SA-MP forums use the 'data' tag, so it would be easier to do it that way.

And you're welcome
Thank you!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)