PDA

View Full Version : strcmp


Cowboy
05/04/2012, 09:17 PM
I get an incorrect password even if the password is correct. Password's hash prints the correct output which is in the file, I think I am using strcmp wrong.

case 2:
{
if(!response)
{
Kick(playerid);
}
else
{
new buf[129];
INI_ParseFile(UserPath(playerid), "LoadUserData_%s", .bExtra = true, .extra = playerid);
WP_Hash(buf, sizeof (buf), inputtext);
if(strcmp(PlayerInfo[playerid][pPassword], buf, true))
{
SendClientMessage(playerid, Green, "Logged");
}
else
{
ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "Account", "Login to your account\n\nWrong password\n\nEnter your password:", "Login", "Quit");
}
printf("Password: %s | %s", buf, inputtext);
return 1;
}
}

Please help.

[HiC]TheKiller
05/04/2012, 09:54 PM
strcmp returns 0 rather than 1 if the strings match.

Toreno
05/04/2012, 10:06 PM
if(!strcmp(PlayerInfo[playerid][pPassword], buf, false))

Cowboy
05/04/2012, 10:15 PM
Toreno, now it logs me in even if the password is incorrect.

BlackBank
05/04/2012, 10:20 PM
if(strcmp(inputtext, buf, true) == 0)

EDIT:
My fault, can you print PlayerInfo[playerid][pPassword], and check if it is encrypted/hashed.

Cowboy
05/04/2012, 10:29 PM
It is empty, and that piece of line didn't work. :)

BlackBank
05/04/2012, 10:32 PM
It is empty, and that piece of line didn't work. :)

You have saved the hashed password into your ini account?

Cowboy
05/04/2012, 10:34 PM
Yes, it is written correctly and this: printf("Password: %s | %s", buf, inputtext); prints out the exact same string as in the file.

BlackBank
05/04/2012, 10:38 PM
But if you print this:
printf("PlayerInfo[Password]: %s", PlayerInfo[playerid][pPassword]);
Does it says that pPassword is empty?

Cowboy
05/04/2012, 10:39 PM
Yes, do you want me to show how I load the password?

BlackBank
05/04/2012, 10:41 PM
Yes, do you want me to show how I load the password?

Yea, i think the problem isn't in this code, but in the load section. ;)

Cowboy
05/04/2012, 10:43 PM
forward @LoadUserData(playerid, name[], value[]);

enum pInfo
{
pPassword[129],
}
new PlayerInfo[MAX_PLAYERS][pInfo];


@LoadUserData(playerid, name[], value[])
{
INI_String("Password", PlayerInfo[playerid][pPassword], 129);
return 1;
}

stock UserPath(playerid)
{
new string[128], pName[MAX_PLAYER_NAME];
GetPlayerName(playerid, pName, sizeof(pName));
format(string, sizeof(string), USER_FILE_PATH, pName);
return string;
}

BlackBank
05/04/2012, 11:06 PM
Change this:
INI_ParseFile(UserPath(playerid), "LoadUserData_%s", .bExtra = true, .extra = playerid);

To:
INI_ParseFile(UserPath(playerid), "LoadUserData", .bExtra = true, .extra = playerid, .bPassTag = true);

The first one will load with the methode TAG, the latest one not and will load the whole file. ;)

Cowboy
06/04/2012, 10:52 AM
The password variable is still empty, and it doesn't work :(

BlackBank
06/04/2012, 11:11 AM
forward LoadUserData(playerid, name[], value[]);

enum pInfo
{
pPassword[129],
}
new PlayerInfo[MAX_PLAYERS][pInfo];


public LoadUserData(playerid, name[], value[])
{
INI_String("Password", PlayerInfo[playerid][pPassword], 129);
return 1;
}

stock UserPath(playerid)
{
new string[128], pName[MAX_PLAYER_NAME];
GetPlayerName(playerid, pName, sizeof(pName));
format(string, sizeof(string), USER_FILE_PATH, pName);
return string;
}

And if you use this code?

Cowboy
06/04/2012, 03:17 PM
Variable still empty :(

Cowboy
06/04/2012, 03:42 PM
Fixed. :)

BlackBank
06/04/2012, 04:46 PM
Fixed. :)

How did you fix it? :P

Cowboy
06/04/2012, 09:30 PM
I was parsing incorrectly :)