SA-MP Forums Archive
Checking if a string is empty, shouldn't this do it? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Checking if a string is empty, shouldn't this do it? (/showthread.php?tid=573847)



Checking if a string is empty, shouldn't this do it? - Dokins - 10.05.2015

pawn Код:
if(strcmp(password, inputtext, false) == 0)
            {
I may be ill informed, but shouldn't a returned 0 strcmp return 0?

If I hit enter, it allows access to the server without a password! (MAJOR EXPLOIT!)

Thanks for any assistance.


Re: Checking if a string is empty, shouldn't this do it? - ChromeAmazing - 11.05.2015

PHP код:
if(udb_hash(inputtext) == PlayerInfo[playerid][Password])// THIS HASHES THE PASSWORD, BE SURE TO HAVE WHIRLPOOL
{
    
GivePlayerMoney(playeridPlayerInfo[playerid][Money]); // GIVES MONEY
    
SpawnPlayer(playerid); // SPAWNS PLAYER
}
else
{
    
ShowLoginDialog(playerid); // RESHOWS YOUR DIALOG, CHANGE IF NEEDED
    
SendClientMessage(playeridGREY"[SERVER]: You have entered an incorrect password."); // SAYS INCORRECT PW
    
LoginAttempt[playerid] ++; //ADDS A LOGIN ATTEMPT
    
if(LoginAttempt[playerid] == 2// TO MANY AND HE'S KICKED
    
{
    
LoginAttempt[playerid] = 0;
    
Kick(playerid);
    }




Re: Checking if a string is empty, shouldn't this do it? - Abagail - 11.05.2015

Strcmp returns 0 when the input MATCHES. You should use:

pawn Код:
if(!strlen(password) || isnull(password))
You should have isnull if you have ZCMD.


Re: Checking if a string is empty, shouldn't this do it? - MP2 - 11.05.2015

isnull is more efficient than strlen.


Re: Checking if a string is empty, shouldn't this do it? - Dokins - 11.05.2015

Thanks for the responses, I appreciate it.