SA-MP Forums Archive
String comparing - hashed (djson and whirlpool) - 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: String comparing - hashed (djson and whirlpool) (/showthread.php?tid=325726)



String comparing - hashed (djson and whirlpool) - sim_sima - 14.03.2012

Hi guys. I am working on a login/register system, which is using djson and whirlpool.
It almost works fine. When the plaayer registers, his password is hashed and saved, no problems there.

But when someone is trying to log in to a registered account, it just doesn't work. It keeps saying wrong password.
Here is the code from the login dialog:
pawn Код:
if(dialogid == 2)
    {
        if(!response)
        {
            StopAudioStreamForPlayer(playerid);
            SendClientMessage(playerid, COLOR_SYSTEMRED, "( ! ) You must log in to play on this server. Please come again soon");
            Kick(playerid);
            gPlayerLogged[playerid] = 0;
        }
        new hashed_password[129];
        WP_Hash(hashed_password, sizeof(hashed_password), inputtext);
        if(!strcmp(hashed_password, dj(file, "Password")))
        {
            ShowPlayerDialog(playerid, 2, DIALOG_STYLE_PASSWORD, "{FFFF00}Hopes Hills RPG Account", "{AF0000}Incorrect Password!\n{FFFFFF}Enter your Password", "Login", "Quit");
        }
        else
        {
            SendClientMessage(playerid, COLOR_GREEN, "( ! ) You have successfully Logged In!");
            GivePlayerMoney(playerid, djInt(file, "Money"));
            PlayerInfo[playerid][pBanned] = djInt(file, "Banned");
            gPlayerLogged[playerid] = 1;
            OnceLogged[playerid] = 1;
        }
Hope someone can help me. Thank you.


Re: String comparing - hashed (djson and whirlpool) - eesh - 14.03.2012

maybe its not saving the full password in the file. open the file and compare the hashes with an scm or printf


Re: String comparing - hashed (djson and whirlpool) - Vince - 14.03.2012

strcmp returns 0 on success, not 1. Remove that exclamation mark in the conditional and you should be set.


Re: String comparing - hashed (djson and whirlpool) - sim_sima - 14.03.2012

Quote:
Originally Posted by Vince
Посмотреть сообщение
strcmp returns 0 on success, not 1. Remove that exclamation mark in the conditional and you should be set.
Hmm. Now i can log in no matter what password i type


Re: String comparing - hashed (djson and whirlpool) - sim_sima - 16.03.2012

*BUMP*
Right now my code looks like this, still not working:
pawn Код:
if(dialogid == 2)
    {
        if(!response)
        {
            StopAudioStreamForPlayer(playerid);
            SendClientMessage(playerid, COLOR_SYSTEMRED, "( ! ) You must log in to play on this server. Please come again soon");
            Kick(playerid);
            gPlayerLogged[playerid] = 0;
        }
        new hashed_password[129];
        WP_Hash(hashed_password, sizeof(hashed_password), inputtext);
        if(strcmp(hashed_password, dj(file, "Password"), true))
        {
            SendClientMessage(playerid, COLOR_GREEN, "( ! ) You have successfully Logged In!");
            GivePlayerMoney(playerid, djInt(file, "Money"));
            PlayerInfo[playerid][pBanned] = djInt(file, "Banned");
            gPlayerLogged[playerid] = 1;
            OnceLogged[playerid] = 1;
        }
        else
        {
            ShowPlayerDialog(playerid, 2, DIALOG_STYLE_PASSWORD, "{FFFF00}Hopes Hills RPG Account", "{AF0000}Incorrect Password!\n{FFFFFF}Enter your Password", "Login", "Quit");
        }
Hope you can help.


Re: String comparing - hashed (djson and whirlpool) - T0pAz - 16.03.2012

pawn Код:
if(dialogid == 2)
    {
        if(!response)
        {
            StopAudioStreamForPlayer(playerid);
            SendClientMessage(playerid, COLOR_SYSTEMRED, "( ! ) You must log in to play on this server. Please come again soon");
            Kick(playerid);
            gPlayerLogged[playerid] = 0;
        }
        new hashed_password[129];
        WP_Hash(hashed_password, sizeof(hashed_password), inputtext);
        if(!strcmp(hashed_password, dj(file, "Password"), true))
        {
            SendClientMessage(playerid, COLOR_GREEN, "( ! ) You have successfully Logged In!");
            GivePlayerMoney(playerid, djInt(file, "Money"));
            PlayerInfo[playerid][pBanned] = djInt(file, "Banned");
            gPlayerLogged[playerid] = 1;
            OnceLogged[playerid] = 1;
        }
        else
        {
            ShowPlayerDialog(playerid, 2, DIALOG_STYLE_PASSWORD, "{FFFF00}Hopes Hills RPG Account", "{AF0000}Incorrect Password!\n{FFFFFF}Enter your Password", "Login", "Quit");
        }



Re: String comparing - hashed (djson and whirlpool) - sim_sima - 16.03.2012

Quote:
Originally Posted by T0pAz
Посмотреть сообщение
pawn Код:
if(dialogid == 2)
    {
        if(!response)
        {
            StopAudioStreamForPlayer(playerid);
            SendClientMessage(playerid, COLOR_SYSTEMRED, "( ! ) You must log in to play on this server. Please come again soon");
            Kick(playerid);
            gPlayerLogged[playerid] = 0;
        }
        new hashed_password[129];
        WP_Hash(hashed_password, sizeof(hashed_password), inputtext);
        if(!strcmp(hashed_password, dj(file, "Password"), true))
        {
            SendClientMessage(playerid, COLOR_GREEN, "( ! ) You have successfully Logged In!");
            GivePlayerMoney(playerid, djInt(file, "Money"));
            PlayerInfo[playerid][pBanned] = djInt(file, "Banned");
            gPlayerLogged[playerid] = 1;
            OnceLogged[playerid] = 1;
        }
        else
        {
            ShowPlayerDialog(playerid, 2, DIALOG_STYLE_PASSWORD, "{FFFF00}Hopes Hills RPG Account", "{AF0000}Incorrect Password!\n{FFFFFF}Enter your Password", "Login", "Quit");
        }
Thhanks, but does not work.


Re: String comparing - hashed (djson and whirlpool) - T0pAz - 16.03.2012

pawn Код:
if(dialogid == 2)
    {
        if(!response)
        {
            StopAudioStreamForPlayer(playerid);
            SendClientMessage(playerid, COLOR_SYSTEMRED, "( ! ) You must log in to play on this server. Please come again soon");
            Kick(playerid);
            gPlayerLogged[playerid] = 0;
        }
        new hashed_password[129];
        WP_Hash(hashed_password, sizeof(hashed_password), inputtext);
        printf("WP_Hash: %s | Data: %s", hashed_password, dj(file, "Password"));
        if(!strcmp(hashed_password, dj(file, "Password"), true))
        {
            SendClientMessage(playerid, COLOR_GREEN, "( ! ) You have successfully Logged In!");
            GivePlayerMoney(playerid, djInt(file, "Money"));
            PlayerInfo[playerid][pBanned] = djInt(file, "Banned");
            gPlayerLogged[playerid] = 1;
            OnceLogged[playerid] = 1;
        }
        else
        {
            ShowPlayerDialog(playerid, 2, DIALOG_STYLE_PASSWORD, "{FFFF00}Hopes Hills RPG Account", "{AF0000}Incorrect Password!\n{FFFFFF}Enter your Password", "Login", "Quit");
        }
Show the server log.


Re: String comparing - hashed (djson and whirlpool) - sim_sima - 16.03.2012

Quote:
Originally Posted by T0pAz
Посмотреть сообщение
pawn Код:
if(dialogid == 2)
    {
        if(!response)
        {
            StopAudioStreamForPlayer(playerid);
            SendClientMessage(playerid, COLOR_SYSTEMRED, "( ! ) You must log in to play on this server. Please come again soon");
            Kick(playerid);
            gPlayerLogged[playerid] = 0;
        }
        new hashed_password[129];
        WP_Hash(hashed_password, sizeof(hashed_password), inputtext);
        printf("WP_Hash: %s | Data: %s", hashed_password, dj(file, "Password"));
        if(!strcmp(hashed_password, dj(file, "Password"), true))
        {
            SendClientMessage(playerid, COLOR_GREEN, "( ! ) You have successfully Logged In!");
            GivePlayerMoney(playerid, djInt(file, "Money"));
            PlayerInfo[playerid][pBanned] = djInt(file, "Banned");
            gPlayerLogged[playerid] = 1;
            OnceLogged[playerid] = 1;
        }
        else
        {
            ShowPlayerDialog(playerid, 2, DIALOG_STYLE_PASSWORD, "{FFFF00}Hopes Hills RPG Account", "{AF0000}Incorrect Password!\n{FFFFFF}Enter your Password", "Login", "Quit");
        }
Show the server log.
Nothing unusual there.
Код:
----------
Loaded log file: "server_log.txt".
----------

SA-MP Dedicated Server
----------------------
v0.3d-R2, ©2005-2011 SA-MP Team

[18:49:00] filterscripts = ""  (string)
[18:49:00] 
[18:49:00] Server Plugins
[18:49:00] --------------
[18:49:00]  Loading plugin: sscanf
[18:49:00] 

[18:49:00]  ===============================

[18:49:00]       sscanf plugin loaded.     

[18:49:00]    © 2009 Alex "******" Cole

[18:49:00]    0.3d-R2 500 Players "dnee"

[18:49:00]  ===============================

[18:49:00]   Loaded.
[18:49:00]  Loading plugin: Whirlpool
[18:49:00]  
[18:49:00]  ==================
[18:49:00]  
[18:49:00]   Whirlpool loaded
[18:49:00]  
[18:49:00]  ==================
[18:49:00]  
[18:49:00]   Loaded.
[18:49:00]  Loaded 2 plugins.

[18:49:00] 
[18:49:00] Filterscripts
[18:49:00] ---------------
[18:49:00]   Loaded 0 filterscripts.

[18:49:00] 
----------------------------------
[18:49:00] RPG Gamemode Loaded!
[18:49:00] ----------------------------------

[18:49:00] Number of vehicle models: 0
[18:49:19] Incoming connection: 192.168.1.6:57031
[18:49:19] [join] krogsgaard20 has joined the server (0:192.168.1.6)
[18:49:33] [part] krogsgaard20 has left the server (0:2)

----------
Loaded log file: "server_log.txt".
----------

SA-MP Dedicated Server
----------------------
v0.3d-R2, ©2005-2011 SA-MP Team

[19:15:46] filterscripts = ""  (string)
[19:15:46] 
[19:15:46] Server Plugins
[19:15:46] --------------
[19:15:46]  Loading plugin: sscanf
[19:15:46] 

[19:15:46]  ===============================

[19:15:46]       sscanf plugin loaded.     

[19:15:46]    © 2009 Alex "******" Cole

[19:15:46]    0.3d-R2 500 Players "dnee"

[19:15:46]  ===============================

[19:15:46]   Loaded.
[19:15:46]  Loading plugin: Whirlpool
[19:15:46]  
[19:15:46]  ==================
[19:15:46]  
[19:15:46]   Whirlpool loaded
[19:15:46]  
[19:15:46]  ==================
[19:15:46]  
[19:15:46]   Loaded.
[19:15:46]  Loaded 2 plugins.

[19:15:46] 
[19:15:46] Filterscripts
[19:15:46] ---------------
[19:15:46]   Loaded 0 filterscripts.

[19:15:46] 
----------------------------------
[19:15:46] RPG Gamemode Loaded!
[19:15:46] ----------------------------------

[19:15:46] Number of vehicle models: 0
[19:16:07] Incoming connection: 192.168.1.6:62980
[19:16:08] [join] krogsgaard20 has joined the server (0:192.168.1.6)
[19:16:27] [part] krogsgaard20 has left the server (0:1)

----------
Loaded log file: "server_log.txt".
----------

SA-MP Dedicated Server
----------------------
v0.3d-R2, ©2005-2011 SA-MP Team

[19:16:47] filterscripts = ""  (string)
[19:16:47] 
[19:16:47] Server Plugins
[19:16:47] --------------
[19:16:47]  Loading plugin: sscanf
[19:16:47] 

[19:16:47]  ===============================

[19:16:47]       sscanf plugin loaded.     

[19:16:47]    © 2009 Alex "******" Cole

[19:16:47]    0.3d-R2 500 Players "dnee"

[19:16:47]  ===============================

[19:16:47]   Loaded.
[19:16:47]  Loading plugin: Whirlpool
[19:16:47]  
[19:16:47]  ==================
[19:16:47]  
[19:16:47]   Whirlpool loaded
[19:16:47]  
[19:16:47]  ==================
[19:16:47]  
[19:16:47]   Loaded.
[19:16:47]  Loaded 2 plugins.

[19:16:47] 
[19:16:47] Filterscripts
[19:16:47] ---------------
[19:16:47]   Loaded 0 filterscripts.

[19:16:47] 
----------------------------------
[19:16:47] RPG Gamemode Loaded!
[19:16:47] ----------------------------------

[19:16:47] Number of vehicle models: 0
[19:17:05] Incoming connection: 192.168.1.6:50650
[19:17:05] [join] krogsgaard20 has joined the server (0:192.168.1.6)
[19:17:10] [part] krogsgaard20 has left the server (0:1)
[19:17:13] --- Server Shutting Down.



Re: String comparing - hashed (djson and whirlpool) - T0pAz - 16.03.2012

Quote:
Originally Posted by sim_sima
Посмотреть сообщение
Nothing unusual there.
Код:
----------
Loaded log file: "server_log.txt".
----------

SA-MP Dedicated Server
----------------------
v0.3d-R2, ©2005-2011 SA-MP Team

[18:49:00] filterscripts = ""  (string)
[18:49:00] 
[18:49:00] Server Plugins
[18:49:00] --------------
[18:49:00]  Loading plugin: sscanf
[18:49:00] 

[18:49:00]  ===============================

[18:49:00]       sscanf plugin loaded.     

[18:49:00]    © 2009 Alex "******" Cole

[18:49:00]    0.3d-R2 500 Players "dnee"

[18:49:00]  ===============================

[18:49:00]   Loaded.
[18:49:00]  Loading plugin: Whirlpool
[18:49:00]  
[18:49:00]  ==================
[18:49:00]  
[18:49:00]   Whirlpool loaded
[18:49:00]  
[18:49:00]  ==================
[18:49:00]  
[18:49:00]   Loaded.
[18:49:00]  Loaded 2 plugins.

[18:49:00] 
[18:49:00] Filterscripts
[18:49:00] ---------------
[18:49:00]   Loaded 0 filterscripts.

[18:49:00] 
----------------------------------
[18:49:00] RPG Gamemode Loaded!
[18:49:00] ----------------------------------

[18:49:00] Number of vehicle models: 0
[18:49:19] Incoming connection: 192.168.1.6:57031
[18:49:19] [join] krogsgaard20 has joined the server (0:192.168.1.6)
[18:49:33] [part] krogsgaard20 has left the server (0:2)

----------
Loaded log file: "server_log.txt".
----------

SA-MP Dedicated Server
----------------------
v0.3d-R2, ©2005-2011 SA-MP Team

[19:15:46] filterscripts = ""  (string)
[19:15:46] 
[19:15:46] Server Plugins
[19:15:46] --------------
[19:15:46]  Loading plugin: sscanf
[19:15:46] 

[19:15:46]  ===============================

[19:15:46]       sscanf plugin loaded.     

[19:15:46]    © 2009 Alex "******" Cole

[19:15:46]    0.3d-R2 500 Players "dnee"

[19:15:46]  ===============================

[19:15:46]   Loaded.
[19:15:46]  Loading plugin: Whirlpool
[19:15:46]  
[19:15:46]  ==================
[19:15:46]  
[19:15:46]   Whirlpool loaded
[19:15:46]  
[19:15:46]  ==================
[19:15:46]  
[19:15:46]   Loaded.
[19:15:46]  Loaded 2 plugins.

[19:15:46] 
[19:15:46] Filterscripts
[19:15:46] ---------------
[19:15:46]   Loaded 0 filterscripts.

[19:15:46] 
----------------------------------
[19:15:46] RPG Gamemode Loaded!
[19:15:46] ----------------------------------

[19:15:46] Number of vehicle models: 0
[19:16:07] Incoming connection: 192.168.1.6:62980
[19:16:08] [join] krogsgaard20 has joined the server (0:192.168.1.6)
[19:16:27] [part] krogsgaard20 has left the server (0:1)

----------
Loaded log file: "server_log.txt".
----------

SA-MP Dedicated Server
----------------------
v0.3d-R2, ©2005-2011 SA-MP Team

[19:16:47] filterscripts = ""  (string)
[19:16:47] 
[19:16:47] Server Plugins
[19:16:47] --------------
[19:16:47]  Loading plugin: sscanf
[19:16:47] 

[19:16:47]  ===============================

[19:16:47]       sscanf plugin loaded.     

[19:16:47]    © 2009 Alex "******" Cole

[19:16:47]    0.3d-R2 500 Players "dnee"

[19:16:47]  ===============================

[19:16:47]   Loaded.
[19:16:47]  Loading plugin: Whirlpool
[19:16:47]  
[19:16:47]  ==================
[19:16:47]  
[19:16:47]   Whirlpool loaded
[19:16:47]  
[19:16:47]  ==================
[19:16:47]  
[19:16:47]   Loaded.
[19:16:47]  Loaded 2 plugins.

[19:16:47] 
[19:16:47] Filterscripts
[19:16:47] ---------------
[19:16:47]   Loaded 0 filterscripts.

[19:16:47] 
----------------------------------
[19:16:47] RPG Gamemode Loaded!
[19:16:47] ----------------------------------

[19:16:47] Number of vehicle models: 0
[19:17:05] Incoming connection: 192.168.1.6:50650
[19:17:05] [join] krogsgaard20 has joined the server (0:192.168.1.6)
[19:17:10] [part] krogsgaard20 has left the server (0:1)
[19:17:13] --- Server Shutting Down.
You didn't even logged in. Those print function haven't got called.