STRCMP doesn't function properly with Whirlpool
#1

Well, I am busy with a register system. I always used this method with MYSQL, and it always worked, until I used Whirlpool hash.

This is my code to check if the two passwords match:
pawn Код:
stock PlayerLogin(playerid, password[])
{
    new query[256];
    WP_Hash(password, 129, password);
    printf("Login: %s", password);
    format(query, sizeof(query), "SELECT `password` FROM `users` WHERE `username` = '%s'", PlayerName(playerid));
    mysql_query(query);
    mysql_store_result();
    if(mysql_fetch_row_format(query))
    {
        sscanf(query, "s[129]", PlayerInfo[playerid][pPassword]);
    }
    mysql_free_result();
    printf("Password: %s", PlayerInfo[playerid][pPassword]);
//  if(!strcmp(password, PlayerInfo[playerid][pPassword], false))
    if (strcmp(password, PlayerInfo[playerid][pPassword]) == 0)
//   if(!strcmp(password, PlayerInfo[playerid][pPassword]))
    {
        SendClientMessage(playerid, -1, "You are now logged in.");
        StoreAccountInfo(playerid);
        SetPlayerMoney(playerid, PlayerInfo[playerid][pMoney]);
        pLogged[playerid] = 1;
        return 1;
    }
    else
    {
        SendClientMessage(playerid, COLOR_RED, "ERROR: Incorrect password!");
        format(query, sizeof(query), "{FFFFFF}Welcome {008B8B}%s, \n{FFFFFF}Your account exists, please login.", PlayerName(playerid));
        ShowPlayerDialog(playerid, 1337, DIALOG_STYLE_INPUT, "Login", query, "Login", "Cancel");
        return 0;
    }
}
As you can see I print the password the player entered, and the password which gets stored by MYSQL.

When I register with the password "lol", it returns this password:
Код:
22FB46E1955A8AEB31C59D79D887D02AF2D1BC4524E85AAFA2455CC78BC0147B10DD477201D147E2F5CA910BB43D982320478B9D179DDDE85F4806497FE2EE68
So, when I login it prints the following:
Код:
Login: 22FB46E1955A8AEB31C59D79D887D02AF2D1BC4524E85AAFA2455CC78BC0147B10DD477201D147E2F5CA910BB43D982320478B9D179DDDE85F4806497FE2EE68
Password: 22FB46E1955A8AEB31C59D79D887D02AF2D1BC4524E85AAFA2455CC78BC0147B10DD477201D147E2F5CA910BB43D982320478B9D179DDDE85F4806497FE2EE68
As you can see it matches, but STRCMP says it doesn't (it goes to the wrong password part).

I've tried many methods to compare the passwords out of frustration, but no results.

I hope you can help me.
Reply
#2

you can't use query in dialog but okay....

try if(!strcmp.... so put !
Reply
#3

@ The Query part: Read properly, I am not using a query in a dialog.
@ if(!strcmp: I've already tried that as you can see in the commented strcmps.

Thanks for trying
Reply
#4

Try to create a new variable to store hashed password. Then compare it with saved password.
Reply
#5

try
pawn Код:
stock PlayerLogin(playerid, password[])
{
    new query[256];
    new buf[129];
    new savingstring[128];
    WP_Hash(buf, 129, password);
    printf("Login: %s", password);
    format(query, sizeof(query), "SELECT `password` FROM `users` WHERE `username` = '%s'", PlayerName(playerid));
    mysql_query(query);
    mysql_store_result();
    if(mysql_fetch_row_format(query))
    {
        mysql_fetch_field_row(savingstring, "password");
        PlayerInfo[playerid][pPassword] = strval(savingstring);
    }
    mysql_free_result();
    printf("Password: %s", PlayerInfo[playerid][pPassword]);
    if(strval(password) == PlayerInfo[playerid][pPassword])
    {
        SendClientMessage(playerid, -1, "You are now logged in.");
        StoreAccountInfo(playerid);
        SetPlayerMoney(playerid, PlayerInfo[playerid][pMoney]);
        pLogged[playerid] = 1;
        return 1;
    }
    else
    {
        SendClientMessage(playerid, COLOR_RED, "ERROR: Incorrect password!");
        format(query, sizeof(query), "{FFFFFF}Welcome {008B8B}%s, \n{FFFFFF}Your account exists, please login.", PlayerName(playerid));
        ShowPlayerDialog(playerid, 1337, DIALOG_STYLE_INPUT, "Login", query, "Login", "Cancel");
        return 0;
    }
}
Reply
#6

Quote:
Originally Posted by =WoR=Varth
Посмотреть сообщение
Try to create a new variable to store hashed password. Then compare it with saved password.
I did that, but now it works vice versa. All passwords (the right or wrong ones) will move the player to the successfully logged in part.

Edit: @ The post above me:
Didn't work, wrong password all the time (obviously, strval isn't related to my problem, why would you convert the hashed password into an integer?)
Reply
#7

SOLVED, thanks!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)