Y_INI saving/loading problem
#1

I have a problem with my login system.

When the player connects the first time, they can register perfectly, and it creates their save file.
But if they relog, they need to login... fine, but when they enter their password they used when they registered, it says "Incorrect Password".

Here is my code:
Loading, saving:
Код:
forward LoadUser_data(playerid, name[], value[]);
public LoadUser_data(playerid, name[], value[])
{
	INI_Int("Password",PlayerInfo[playerid][pPass]);
	INI_Int("Cash", PlayerInfo[playerid][pCash]);
	INI_Int("Skin",PlayerInfo[playerid][pSkin]);
	INI_Int("Admin", PlayerInfo[playerid][pAdmin]);
	return 1;
}

forward SaveChar(playerid);
public SaveChar(playerid)
{
    if(!IsPlayerConnected(playerid)) return 1;
    if(GetPVarInt(playerid, "prelogin") == 1) return 1;
    if(GetPVarInt(playerid, "Quiz") == 1) return print("Did not save, in quiz.");
    if(Connected[playerid] != 1) return print("Did not save, not logged in.");
	if(AdminDuty[playerid] == 1) return print("Did not save, admin duty.");
	
	new INI:File = INI_Open(UserPath(playerid));
	INI_SetTag(File,"Data");
	INI_WriteInt(File, "Cash", PlayerInfo[playerid][pCash]);
	INI_WriteInt(File, "Skin", PlayerInfo[playerid][pSkin]);
    INI_WriteInt(File, "Admin", PlayerInfo[playerid][pAdmin]);
    
    INI_Close(File);
	return 1;
}
Dialogs, and Onplayerconnect:
Код:
public OnPlayerConnect(playerid)
{
    new PlayerIp[32];
	GetPlayerIp(playerid, PlayerIp, 32);
	
    GetPlayerIp(playerid, PlayerInfo[playerid][pIp], 50);
	SetPlayerColor(playerid, 0xFFFFFF00);
	SetPlayerSkillLevel(playerid, WEAPONSKILL_PISTOL, 1);
	
	SetPVarInt(playerid, "prelogin", 1);
	
    if(fexist(UserPath(playerid)))
    {
        new str[128], string[256], IP[24];
    
        INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
        
        GetPlayerIp(playerid, IP, sizeof(IP));
        format(str, sizeof(str), "Login - %s", GetName(playerid));
	    format(string, sizeof(string), "Welcome to Legion of Los Angeles, %s \n\n IP Address: %s \n\n That name you are using is registered, please login below.", GetName(playerid), IP);
	    ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, str, string, "Login", "Cancel");
    }
    else
    {
        new str[128], string[164], IP[24];
	    format(str, sizeof(str), "Register - %s", GetName(playerid));
	    format(string, sizeof(string), "Welcome to Legion of Los Angeles, %s \n\n IP Address: %s \n\n You may register an account by entering a desired password here:", GetName(playerid), IP);
	    ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, str, string, "Register", "Cancel");
    }
    return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch( dialogid )
    {
        case DIALOG_REGISTER:
        {
            if (!response) return Kick(playerid);
            if(response)
            {
                if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, ""COL_WHITE"Registering...",""COL_RED"You have entered an invalid password.\n"COL_WHITE"Type your password below to register a new account.","Register","Quit");
                
                new skin = random(299);
                
                new INI:File = INI_Open(UserPath(playerid));
	            INI_SetTag(File, "Data");
	            INI_WriteInt(File,"Password",udb_hash(inputtext));
	            INI_Close(File);
                
                PlayerInfo[playerid][pSkin] = skin;
                PlayerInfo[playerid][pCash] = 10000;
				PlayerInfo[playerid][pAdmin] = 0;
				
                SetSpawnInfo(playerid, 0, skin, 1642.6699, -2238.2620, 13.4974, 177.0089, 0, 0, 0, 0, 0, 0);
                SpawnPlayer(playerid);
                SetCameraBehindPlayer(playerid);
                
                SetPVarInt(playerid, "prelogin", 0);
                AdminDuty[playerid] = 0;
                Connected[playerid] = 1;
               // SaveChar(playerid);
                
            }
        }

        case DIALOG_LOGIN:
        {
            if ( !response ) return Kick ( playerid );
            if( response )
            {
                if(udb_hash(inputtext) != PlayerInfo[playerid][pPass]) return ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login", "Incorrect Password. \nPlease try again.", "Login", "Cancel");
                if(udb_hash(inputtext) == PlayerInfo[playerid][pPass])
                {
                    INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
                    GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
                    SetSpawnInfo(playerid, 0, PlayerInfo[playerid][pSkin], 1642.6699, -2238.2620, 13.4974, 177.0089, 0, 0, 0, 0, 0, 0);
	                SpawnPlayer(playerid);
	                SetCameraBehindPlayer(playerid);
	                
	                SetPVarInt(playerid, "prelogin", 0);
	                Connected[playerid] = 1;
					AdminDuty[playerid] = 0;
                }
                return 1;
            }
        }
    }
    return 1;
}
Please help me
Reply
#2

Starting from scratch... I have a server I have already made, but redoing it. So wanting to start again
Reply
#3

I was using the same hashing in my old server... What hashing could I use instead? and could you help me please?
Is that my problem? the hashing?
Reply
#4

Do you know what 'The' problem is?
Reply
#5

What if I use whirlpool to hash instead?
Reply
#6

Use whirlpool and for salting generate a random string, add it to the password when someone registers and save it in the players file. Then when that player tries to login, add that saved string to his input, hash it and compare it. Also shoudn't the password be saved as a string instead of int (I can't even see where you save it)?
Reply


Forum Jump:


Users browsing this thread: 6 Guest(s)