login error: Whirlpool and y_ini
#1

Problem:

i've made my own admin/register/login system, everything works fine, player registers, it hashes and saves password to Users/%s.ini (%s = player name) as i wanted it to, but when player tries to login, the password they entered can be wrong, but they login successfully.

Code i used:

Quote:

I removed the unneeded codes and changed the messages to plain text, to prevent people from stealing.

Code:
#include <a_samp>
#include <YSI\y_ini>

//DIALOG DEFINITIONS
#define DIALOG_REGISTER 1
#define DIALOG_LOGIN 2
#define DIALOG_SUCCESS_1 3
#define DIALOG_SUCCESS_2 4
#define ADMINLEVEL0 5
#define ADMINLEVEL1 6
#define ADMINLEVEL2 7
#define ADMINLEVEL3 8
#define RCON 9
#define SELF 10

//Saving path definition

#define PATH "Users/%s.ini"

native WP_Hash(buffer[],len,const str[]);

new LOGGEDIN[MAX_PLAYERS];

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

forward LoadUser_data(playerid,name[],value[]);
public LoadUser_data(playerid,name[],value[])
{
    INI_String("Password",PlayerInfo[playerid][pPass],129);
    return 1;
}

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

public OnPlayerConnect(playerid)
{
    LOGGEDIN[playerid] = 0;
    if(fexist(UserPath(playerid)))
    {
		INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
 		new loginname[300];
		GetPlayerName(playerid,loginname,MAX_PLAYER_NAME);
 		format(loginname,300,"%s enter password below to login",loginname);
       	ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_PASSWORD,"Login",loginname,"login","");
       	/////////////////////////////////////////////////////timer
  	}
    else
    {
        new registername[300];
		GetPlayerName(playerid,registername,MAX_PLAYER_NAME);
 		format(registername,300,"%s enter password below to register",registername);
        ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD,"Register",registername,"Register","");
    }
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
	if(LOGGEDIN[playerid] == 1)
	{
	    new INI:File = INI_Open(UserPath(playerid));
    	INI_SetTag(File,"PlayerInfo");
    	INI_Close(File);
    	LOGGEDIN[playerid] = 0;
    }
    return 1;
}


public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == DIALOG_REGISTER)
    {
        if (!response) return Kick(playerid);
        if(response)
            {
          		if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Regester", "You have entered an invalid password!", "Register", "Quit");
			    new registername[300];
				GetPlayerName(playerid,registername,MAX_PLAYER_NAME);
      			format(registername,300,"%s has been register",registername, inputtext);

				new hashpass[129];

				WP_Hash(hashpass,sizeof(hashpass),inputtext);
				new INI:File = INI_Open(UserPath(playerid));

        		INI_SetTag(File,"PlayerInfo");

            	INI_WriteString(File,"Password",hashpass);
                INI_Close(File);

   				LOGGEDIN[playerid] = 1;
   				ShowPlayerDialog(playerid, DIALOG_SUCCESS_1, DIALOG_STYLE_MSGBOX,"Register",registername,"Continue","");
	   			INI_ParseFile(UserPath(playerid), "LoadUser_data", .bExtra = true, .extra = playerid);
				return 1;
        }
    }
    if(dialogid == DIALOG_LOGIN)
    {
        if ( !response ) return Kick ( playerid );
        if( response )
        {
 			new hashpass[129];
   			WP_Hash(hashpass,sizeof(hashpass),inputtext);
			if(!strcmp(hashpass, PlayerInfo[playerid][pPass], false))
			{
					LOGGEDIN[playerid] = 1;
	  				INI_ParseFile(UserPath(playerid), "LoadUser_data", .bExtra = true, .extra = playerid);
					SendClientMessage(playerid, -1, "Login succesful.");
			}
			else
			{
			ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login", "wrong password","Login","Quit");
			return 1;
			}
		}
	}
	return 1;
}
I will rep+ you, if you help. Thank you
Reply
#2

Would you mind to debug it?

pawn Code:
printf("DEBUG: hashpass = \"%s\" and PlayerInfo[playerid][pPass] = \"%s\"", hashpass, PlayerInfo[playerid][pPass]);
if(!strcmp(hashpass, PlayerInfo[playerid][pPass], false))
Go in game and type an incorrect password. Then the correct password and show us the results.
Reply
#3

there is something wrong with loading the ini files, The code seems correct.
Reply
#4

Quote:
Originally Posted by Konstantinos
View Post
Would you mind to debug it?

pawn Code:
printf("DEBUG: hashpass = \"%s\" and PlayerInfo[playerid][pPass] = \"%s\"", hashpass, PlayerInfo[playerid][pPass]);
if(!strcmp(hashpass, PlayerInfo[playerid][pPass], false))
Go in game and type an incorrect password. Then the correct password and show us the results.
you smart "debug" i never evens thought of that
Reply
#5

Quote:
Originally Posted by _Jake_
View Post
there is something wrong with loading the ini files, The code seems correct.
I think it loads fine, the score, cash and adminlevel load fine
Reply
#6

nvm guys, i found out what problem was, it is something to do with my gamemode, so yeah. Thank you.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)