SA-MP Forums Archive
Register System issues. - 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: Register System issues. (/showthread.php?tid=506878)



Register System issues. - rangerxxll - 14.04.2014

Hello.

So I'm having some issues with my registration system. When I register my account, it writes just fine. But upon trying to login - I can login with ANY password. I've also tried to modify it in various ways but issues still occur, such as me not being able to login at all.

Here's my current code. I was following a tutorial, attempting to learn more about the way yini works. If more code is needed, let me know.

pawn Код:
if(dialogid == REGISTER_LOGIN)
    {
        if(!response) return Kick(playerid);
        if(response)
        {
            new hashpass[129];
            WP_Hash(hashpass,sizeof(hashpass),inputtext);
            if(!strcmp(hashpass, pInfo[playerid][pPass], false))
            {
                INI_ParseFile(Path(playerid),"LoadAccount_%s",.bExtra = true, .extra = playerid);
                SendClientMessage(playerid,-1,"Welcome back! You have successfully logged in");
            }
            else
            {
                ShowPlayerDialog(playerid,REGISTER_LOGIN,DIALOG_STYLE_INPUT,"Login","Incorrect Password.","Login","Quit");
                return 1;
            }
         }
    }



Re: Register System issues. - mrkiller90 - 15.04.2014

pawn Код:
if(udb_hash(inputtext) == PlayerInfo[playerid][pPass])
                {
                    INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);



Re: Register System issues. - Chenko - 15.04.2014

Make sure you load the player's password into pInfo before you compare the strings because strcmp will return 0 (aka say the strings match) if one of the strings is empty. So if you don't load the password before you compare them then pInfo[playerid][pPass] will be empty and it will accept any password.


Re: Register System issues. - JacobEdwards - 15.04.2014

This works perfectly for me.

pawn Код:
new HashPass[128];
WP_Hash(HashPass, sizeof(HashPass), inputtext);
if(!strcmp(HashPass, pInfo[playerid][pPass])) {
    INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
} else {
    ShowPlayerDialog(playerid,REGISTER_LOGIN,DIALOG_STYLE_INPUT,"Login","Incorrect Password.","Login","Quit");
    return 1;
}



Re: Register System issues. - rangerxxll - 15.04.2014

Quote:
Originally Posted by Chenko
Посмотреть сообщение
Make sure you load the player's password into pInfo before you compare the strings because strcmp will return 0 (aka say the strings match) if one of the strings is empty. So if you don't load the password before you compare them then pInfo[playerid][pPass] will be empty and it will accept any password.
Not too sure what you mean. Could you show an example? This is my enum:

pawn Код:
enum PlayerInfo
{
    pPass[128],
    pKills,
    pDeaths,
    pVip,
    pAdmin
}



Re: Register System issues. - JacobEdwards - 15.04.2014

Quote:
Originally Posted by mrkiller90
Посмотреть сообщение
pawn Код:
if(udb_hash(inputtext) == PlayerInfo[playerid][pPass])
                {
                    INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
He is not even using that method to hash the passwords.


Re: Register System issues. - rangerxxll - 15.04.2014

Quote:
Originally Posted by JacobEdwards
Посмотреть сообщение
He is not even using that method to hash the passwords.
That's why I ignored his post. I'm using whirlpool, not udbhash stock.


Re: Register System issues. - rangerxxll - 15.04.2014

Quote:
Originally Posted by JacobEdwards
Посмотреть сообщение
This works perfectly for me.

pawn Код:
new HashPass[128];
WP_Hash(HashPass, sizeof(HashPass), inputtext);
if(!strcmp(HashPass, pInfo[playerid][pPass])) {
    INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
} else {
    ShowPlayerDialog(playerid,REGISTER_LOGIN,DIALOG_STYLE_INPUT,"Login","Incorrect Password.","Login","Quit");
    return 1;
}
I'm still able to login with any password upon registering.

pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == REGISTER_REGISTER)
    {
        if(!response)
        {
            Kick(playerid);
        }
        if(response)
        {
            if(!strlen(inputtext))
            {
                SCM(playerid,COLOR_RED, "You must enter a password to register a account.");
                ShowPlayerDialog(playerid, REGISTER_REGISTER, DIALOG_STYLE_INPUT, "Please register a account.", "Register", "Enter", "Leave");
                return 1;
            }
            new hashpass[129];
            WP_Hash(hashpass,sizeof(hashpass),inputtext);
            new INI:file = INI_Open(Path(playerid));
            INI_SetTag(file, "Player Data");
            INI_WriteString(file,"Password",hashpass);
            INI_WriteInt(file, "Kills", 0);
            INI_WriteInt(file, "Deaths", 0);
            INI_WriteInt(file, "Vip", 0);
            INI_WriteInt(file, "Admin", 0);
            INI_Close(file);
            new string[128];
            format(string,sizeof(string), "You've registered at Highschool Roleplay with the password %s", inputtext);
            SCM(playerid,COLOR_GREEN, string);
            ShowPlayerDialog(playerid,REGISTER_LOGIN,DIALOG_STYLE_INPUT,"Login","Enter your password to login.","Login","Quit");
        }
    }
    if(dialogid == REGISTER_LOGIN)
    {
        if(!response) return Kick(playerid);
        if(response)
        {
            new hashpass[129];
            WP_Hash(hashpass,sizeof(hashpass),inputtext);
            if(!strcmp(hashpass, pInfo[playerid][pPass]))
            {
                INI_ParseFile(Path(playerid),"LoadAccount_%s",.bExtra = true, .extra = playerid);
                SendClientMessage(playerid,-1,"Welcome back! You have successfully logged in");
            }
            else
            {
                ShowPlayerDialog(playerid,REGISTER_LOGIN,DIALOG_STYLE_INPUT,"Login","Incorrect Password.","Login","Quit");
                return 1;
            }
         }
    }
    return 1;
}



Re: Register System issues. - JeaSon - 15.04.2014

did you tried changing enum pPass[128] to pPass[129] ? if not then try


Re: Register System issues. - rangerxxll - 15.04.2014

I've tried everything, yes. Even tried making the password a integer instead of a string. I've also tried using udb_has instead of whirlpool. Still nothing. I really dont want to copy and paste and would rather learn my mistakes. I hand-wrote this one myself, minus the udb hash stock and a few minor queries.