MySQL bug
#1

Hello!

Another mysql bug came up, I was editting the users table through PhpMyAdmin, now whenever I try to register a new account it doesn't work, I doesn't create the user row, Maybe it's because now I added Whirlpool as password hasher, I just don't know.


OnPlayerConnect
pawn Код:
new Query[80],pName[24],tstring[164];
    GetPlayerName(playerid,pName,24);
    format(Query,sizeof(Query),"SELECT `Username` FROM `Users` WHERE `Username` = '%s' LIMIT 1;",pName);
    mysql_query(Query);
    mysql_store_result();
    if(mysql_num_rows() != 0)
    {
        format(tstring,sizeof(tstring),"Hey, %s! \nYour account is registered. \nPlease enter your password to login!",pName);
        ShowPlayerDialog(playerid,Logindialog,DIALOG_STYLE_INPUT,"Re gister",tstring,"Register","");
    }
    else
    {
        format(tstring,sizeof(tstring),"Hey, %s! \nYour account is NOT registered.\nPlease type a password to register!",pName);
        ShowPlayerDialog(playerid,Regdialog,DIALOG_STYLE_INPUT,"Lo g in",tstring,"Login","");
    }
    mysql_free_result();
OnDialogResponse
pawn Код:
if(dialogid == Regdialog)
    {
        if(strlen(inputtext) == 0)
        {
            ShowPlayerDialog(playerid,Regdialog,DIALOG_STYLE_INPUT,"Register - Enter your password","You are about to register a new account! \nPlease choose the password for it! \n","Register!","");
        }
        else
        {
            new escpass[100];
            mysql_real_escape_string(inputtext, escpass);
            RegisterPlayer(playerid, escpass);
        }
    }
    if(dialogid == Logindialog)
    {
        if(strlen(inputtext) == 0)
        {
            ShowPlayerDialog(playerid,Logindialog,DIALOG_STYLE_INPUT,"Login","Please enter your passsword to continue!","Login","");
        }
        else
        {
            LoginPlayer(playerid,inputtext);
        }
    }
stocks

pawn Код:
stock RegisterPlayer(playerid, passwordstring[])
{
    new query[235], buf[129];
    WP_Hash(buf,129,passwordstring);
    format(query, sizeof(query), "INSERT INTO `users` (`UserName`,`Password`,`Score`,`Money`,`WantedLevel`,`AdminLevel`,`VipLevel`,`ArmyRights`,`SwatRights`,`SGRights`,`MedicLevel`,`RapistLevel`,`MechanicLevel`,`RobSkill`) VALUES('%s','%s',0,100,0,0,0,0,0,0,0,0,0,0)", GetName(playerid), buf);
    mysql_query(query);
    SendClientMessage(playerid, -1,"You have been succesfuly registered on this server!");
    printf("Hashed pass: %s",buf);
    return 1;
}

stock LoginPlayer(playerid,const password[])
{
    new EscapedText[60];
    new EscapedPass[129];
    new Query[140];
    new buf[129];
    mysql_real_escape_string(password, EscapedText);
    WP_Hash(buf,129,EscapedText);
    mysql_real_escape_string(buf, EscapedPass);
    format(Query,sizeof(Query),"SELECT * FROM `users` WHERE `Username` = '%s' AND `Password` = '%s'",GetName(playerid), EscapedPass);
    mysql_query(Query);
    new rows = mysql_store_result();
    if(rows == 1)
    {
        SendClientMessage(playerid,-1,"You have been logged in!");
        LoadStats(playerid);
    }
    if(!rows)
    {
        new tstring[164];
        SendClientMessage(playerid,-1,"Wrong password!");
        MaxLoginAttempts[playerid]++;
        format(tstring,sizeof(tstring),"Hey, %s! \nYour account is registered. \nPlease enter your password to login!",GetName(playerid));
        ShowPlayerDialog(playerid,Logindialog,DIALOG_STYLE_INPUT,"Re gister",tstring,"Register","");
        if(MaxLoginAttempts[playerid] == 3)
        {
            Kick(playerid);
        }
    }
    mysql_free_result();
    return 1;
}

Thanks in advance
Reply
#2

Try to print all the queries you send so you will know reason, do it this way:
pawn Код:
print (Query);
I assume that, your row size in the table is not large enough.
Reply
#3

Fixed, The query lenght was causing the bug

Anyways, Thanks dude. +rep

EDIT: Looks like the rep system is bugged, I'll give you +rep when the rep system works properly
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)