SA-MP Forums Archive
MySQL Login fail ? - 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: MySQL Login fail ? (/showthread.php?tid=577540)



MySQL Login fail ? - malackovgfx - 12.06.2015

Hello, i have a problem. I made a Login/Register system using MySql, but the problem now is the login. When you try to login even if you put the right password it dosen't work again. here's the onplayerpasswordresponse code:

pawn Код:
forward OnPasswordResponse(playerid);
public OnPasswordResponse(playerid)
{
    new num_fields,num_rows;
    cache_get_data(num_rows,num_fields,dbhandel);
    if(num_fields==1)
    {
        iInfo[playerid][loggt] = 1;
       
        iInfo[playerid][score] = cache_get_field_content_int(0,"score",dbhandel);
    }
    else
    {
        SendClientMessage(playerid, BJELA, "Ukucana lozinka se ne poklapa sa ovim nalogom.");
        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "LOGIN", "UPISITE VASU LOZINK KAKO BI PRISTUPILI SERVERU.", "LOGIN", "OTKAZI");
    }
    return 1;
}
here's the onplayerdialogresponse:
pawn Код:
if(dialogid==DIALOG_LOGIN)
    {
        if(response)
        {
            new name[MAX_PLAYER_NAME],query[128],password[255];
            GetPlayerName(playerid,name,sizeof(name));
            if(strlen(inputtext)>0)
            {
                mysql_escape_string(inputtext,password,dbhandel);
                format(query,sizeof(query),"SELECT * FROM acoounts WHERE username='%s' AND password='%s'",name,password);
                mysql_function_query(dbhandel,query,true,"OnPasswordResponse","i",playerid);
            }
            else
            {
                SendClientMessage(playerid,BJELA,"Upisite vasu lozinku!");
                ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "LOGIN", "UPISITE VASU LOZINK KAKO BI PRISTUPILI SERVERU.", "LOGIN", "OTKAZI");
            }
        }
        else
        {
            Kick(playerid);
        }
        return 1;
    }
Oh and my database/tables


Re: MySQL Login fail ? - mamorunl - 12.06.2015

Let's try this again. Forum crashed on my whilst posting.

1. Primary key is not auto increment
2. Typo in table name in SELECT
3. No encryption on password?


Re: MySQL Login fail ? - malackovgfx - 12.06.2015

Added the primary key on ID and AIed it, no typos found and what do you mean by encryption ? Still can't login


Re: MySQL Login fail ? - Konstantinos - 12.06.2015

Just for your information, you need to check if there are rows not if there is 1 field (which you have more).
pawn Код:
if(num_fields==1)
// to:
if(num_rows)
Also mamorunl means that you should hash the passwords of your players. Check Whirlpool thread for more information.


Re: MySQL Login fail ? - malackovgfx - 12.06.2015

Thank you guys! It works now


Re: MySQL Login fail ? - mamorunl - 12.06.2015

Can you also please fix your signature? It is huge and breaks the forum lay-out.