Can log in with any password [MySQL]
#1

Thanks for your help before, guys!

This time, this is like, I can login with any password in my file.
ex; my pass is 'adawesdawds', I can still login with 'test' or any other random password.
I would like to know how to fix it. Thank you.
pawn Code:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch(dialogid)
    {
        case DIALOG_LOG:
        {
            if(!response) return Kick(playerid);
            new hPass[129];
            new query[100];
            WP_Hash(hPass, 129, inputtext);
            if(strcmp(hPass, pData[playerid][Password]))
            {
                mysql_format(mysql, query, sizeof(query), "SELECT * FROM `players` WHERE `Username` = '%e' LIMIT 1", GPName(playerid));
                mysql_tquery(mysql, query, "OnAccountLoad", "i", playerid);
            }
            else
            {
                MaxLoginAmount[playerid] ++;
                ShowPlayerDialog(playerid, DIALOG_LOG, DIALOG_STYLE_PASSWORD, "Invalid Password.", "The password you have entered for this account is invalid. \nPlease enter the password below:", "Login", "Quit");
            }
            if(MaxLoginAmount[playerid] >= 3)
            {
                SendClientMessage(playerid, COLOR_RED, "SERVER: You have exceeded the max amounts of login attempts [3]. You have been kicked.");
                SetTimerEx("DelayedKick", 1000, false, "i", playerid);
            }
        }
        case DIALOG_REG:
        {
            if(!response) return Kick(playerid);
            if(strlen(inputtext) < 6) return ShowPlayerDialog(playerid, DIALOG_REG, DIALOG_STYLE_PASSWORD, "Invalid Password", "The password you have entered is too small. \nPlease enter a password longer than 6 letters!", "Register", "Quit");
            new query[300];
            WP_Hash(pData[playerid][Password], 129, inputtext);
            mysql_format(mysql, query, sizeof(query), "INSERT INTO `players` (`Username`, `Password`, `IP`, `Money`, `Admin`, `pX`, `pY`, `pZ`) VALUES ('%e', '%s', '%s', 0, 0, 0.0, 0.0, 0.0)", GPName(playerid), pData[playerid][Password], IP[playerid]);
            mysql_tquery(mysql, query, "OnAccountRegister", "i", playerid);
        }
    }
    return 1;
}
Reply
#2

pawn Code:
if(strcmp(hPass, pData[playerid][Password]) == 0)
Reply
#3

Quote:
Originally Posted by PowerPC603
View Post
pawn Code:
if(strcmp(hPass, pData[playerid][Password]) == 0)
Thank you for your help, but now it won't let me enter with my original password nor any other password?
Reply
#4

pawn Code:
if(!strcmp(hPass, pData[playerid][Password]))
Try.
Reply
#5

Quote:
Originally Posted by Sawalha
View Post
pawn Code:
if(!strcmp(hPass, pData[playerid][Password]))
Try.
Same case. Cannot login with the password I used.
Reply
#6

Up..
Reply
#7

Quote:
Originally Posted by LivingLikeYouDo
View Post
Same case. Cannot login with the password I used.
Are you sure? be cause i use it in my saving system.
Can you show me the callback which you used to call player to check if he's registered or not,
like "OnAccountCheck" as many people use it.
Reply
#8

Quote:
Originally Posted by Sawalha
View Post
Are you sure? be cause i use it in my saving system.
Can you show me the callback which you used to call player to check if he's registered or not,
like "OnAccountCheck" as many people use it.
Here ya' go:
pawn Code:
public OnAccountCheck(playerid)
{
    new str[200];
    new rows, fields;
    cache_get_data(rows, fields, mysql);
    if(rows)
    {
        cache_get_field_content(0, "PASS", pData[playerid][Password], mysql, 129);
        pData[playerid][ID] = cache_get_field_content_int(0, "ID");
        format(str, sizeof(str), "Welcome back to Reindience Roleplay, %s! \nLooks like your account is registered, please enter your password below:", GPName(playerid));
        ShowPlayerDialog(playerid, DIALOG_LOG, DIALOG_STYLE_PASSWORD, "Welcome back to Reindience Roleplay!", str, "Login", "Quit");
    }
    else
    {
        format(str, sizeof(str), "Welcome to Reindience Roleplay, %s! \nLooks like your account is not registered, please enter a password below:", GPName(playerid));
        ShowPlayerDialog(playerid, DIALOG_REG, DIALOG_STYLE_PASSWORD, "Welcome to Reindience Roleplay!", str, "Register", "Quit");
    }
    return 1;
}
If any other code is needed, let me know.
Reply
#9

yea, that's the problem, the tutorial you took that from had a mistake , look here:
pawn Code:
cache_get_field_content(0, "PASS", pData[playerid][Password], mysql, 129);
and look here:
pawn Code:
mysql_format(mysql, query, sizeof(query), "INSERT INTO `players` (`Username`, `Password`, `IP`, `Money`, `Admin`, `pX`, `pY`, `pZ`) VALUES ('%e', '%s', '%s', 0, 0, 0.0, 0.0, 0.0)", GPName(playerid), pData[playerid][Password], IP[playerid]);
pawn Code:
`Password and PASS
Syntax mistake, so it will load an empty string, and will return a mysql error in the mysql_log.txt.

Change it to:
pawn Code:
cache_get_field_content(0, "Password", pData[playerid][Password], mysql, 129);
instead of "PASS".
Reply
#10

Quote:
Originally Posted by Sawalha
View Post
yea, that's the problem, the tutorial you took that from had a mistake , look here:
pawn Code:
cache_get_field_content(0, "PASS", pData[playerid][Password], mysql, 129);
and look here:
pawn Code:
mysql_format(mysql, query, sizeof(query), "INSERT INTO `players` (`Username`, `Password`, `IP`, `Money`, `Admin`, `pX`, `pY`, `pZ`) VALUES ('%e', '%s', '%s', 0, 0, 0.0, 0.0, 0.0)", GPName(playerid), pData[playerid][Password], IP[playerid]);
pawn Code:
`Password and PASS
Syntax mistake, so it will load an empty string, and will return a mysql error in the mysql_log.txt.

Change it to:
pawn Code:
cache_get_field_content(0, "Password", pData[playerid][Password], mysql, 129);
instead of "PASS".
Oh, damn it. Thanks for your support, now I can continue my development on my server.
+1
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)