Problem with strcmp
#1

Okay, when someone enters a password in the login dialog, the server will get the players salt (stored in a pSalt enum) and get the inputtext and format them together. The server then uses Whirlpool to hash the salt and password together. I then have this line:
pawn Код:
if(strcmp(HashedInput, PlayerData[playerid][pPass]))
Obviously, HashedInput is the salted and hashed inputtext, and pPass is the actual password from the database. I used print(PlayerData[playerid][pSalt]); to make sure pPass was correct, and it was.

The problem is that when I type an incorrect password, the server thinks that it is correct.

pawn Код:
if(strcmp(HashedInput, PlayerData[playerid][pPass]))
    {
        SendClientMessage(playerid, Col_Green, "Correct.");
    }
    else
    {
        SendClientMessage(playerid, Col_Red, "Incorrect.");
    }
In theory, this piece of code should check if HashedInput and pPass are the same, and if they are, it should say "Correct", and if they're not the same it should say "Incorrect.", right? Well that's not what it's doing. Whatever I write as the password it will say it's correct.
Reply
#2

Change to:
pawn Код:
if(!strcmp(HashedInput, PlayerData[playerid][pPass]))
Returns 0 when both strings are same.

EDIT: Make sure you check if the strings are not null. If a string is null, then it will return 0 as well.
Reply
#3

Ahh thanks. I didn't think this would work since it was showing "Correct" when I typed the correct password but I've just changed it and it's working.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)