UDB_HASH Problem [+REP]
#1

It doesnt work well, it hashes but when i login it says Wrong password

pawn Code:
public OnPlayerConnect(playerid)
{
    if(fexist(UserPath(playerid)))
    {
        SendClientMessage(playerid, COLOR_WHITE, "SERVER: Welcome to Bone County Roleplay, please log in!");
        INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
        ShowDialog(playerid, 2, DIALOG_PASS, "Welcome back to Bone County!", "That username is registered,\nInput your password to login and continue!", "Login", "Exit");
    }
    else
    {
        SendClientMessage(playerid, COLOR_WHITE, "SERVER: Welcome to Bone County Roleplay, please register!");
        ShowDialog(playerid, 1, DIALOG_PASS, "Hi there, Welcome to Bone County!", "Hello new citizen!\n\nWelcome to Bone County, where crime doesn't pay.\nPlease register your citizenship!", "Register", "Exit");
    }
    return 1;
       
}


pawn Code:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch (dialogid)
    {
        case 1: // Register
        {
            if(!response) {
                SendClientMessage(playerid, COLOR_GREY,"    Thanks for coming...");
                Kick(playerid);
            }
            else if(response) {
                if(!strlen(inputtext)) return ShowDialog(playerid, 1, DIALOG_PASS, "Hi there, Welcome to Bone County!", "Hello new citizen!\n\nWelcome to Bone County, where crime doesn't pay.\nPlease register your citizenship!", "Register", "Exit");
                new INI:File = INI_Open(UserPath(playerid));
                INI_SetTag(File,"data");
                INI_WriteInt(File, "Password", udb_hash(inputtext));
                INI_WriteInt(File, "Admin", 0);
                INI_WriteInt(File, "Origin", 0);
                INI_WriteInt(File, "Gender", 0);
                INI_WriteInt(File, "Age", 0);
                INI_WriteFloat(File, "sPosX", 194.485778);
                INI_WriteFloat(File, "sPosY", 1103.993408);
                INI_WriteFloat(File, "sPosZ", 16.347635);
                INI_WriteFloat(File, "sPosA", 30.403614);
                INI_WriteFloat(File, "sHealth", 100);
                INI_WriteFloat(File, "sArmor", 0);
                INI_WriteInt(File, "Money", 2000);
                INI_WriteInt(File, "BankBalance", 20000);
                INI_WriteInt(File, "BankPin", 0);
                INI_WriteInt(File, "Cellphone", 0);
                INI_WriteInt(File, "HouseID", 0);
                INI_WriteInt(File, "CarID", 0);
                INI_WriteInt(File, "Gun1", 0);
                INI_WriteInt(File, "Gun2", 0);
                INI_WriteInt(File, "Gun3", 0);
                INI_WriteInt(File, "Gun4", 0);
                INI_WriteInt(File, "Gun5", 0);
                INI_WriteInt(File, "Gun6", 0);
                INI_WriteInt(File, "Gun7", 0);
                INI_WriteInt(File, "Gun8", 0);
                INI_WriteInt(File, "Gun9", 0);
                INI_WriteInt(File, "Gun10", 0);
                INI_WriteInt(File, "Gun11", 0);
                INI_WriteInt(File, "Gun12", 0);
                INI_WriteInt(File, "Gun13", 0);
                INI_WriteInt(File, "WTChannel", 0);
                INI_WriteInt(File, "Faction", 0);
                INI_WriteInt(File, "FLeader", 0);
                INI_WriteInt(File, "Job", 0);
                INI_WriteInt(File, "sInterior", 0);
                INI_WriteInt(File, "sVW", 0);
                INI_WriteInt(File, "Skin", 1);
                INI_WriteInt(File, "Muted", 0);
                INI_WriteInt(File, "nMute", 0);
                INI_WriteInt(File, "Helper", 0);
                INI_WriteInt(File, "Developer", 0);
                INI_WriteInt(File, "RentingID", 0);
                INI_Close(File);
                INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
                ResetPlayerMoney(playerid);
                GivePlayerMoney(playerid, PlayerInfo[playerid][Money]);
                ClearScreen(playerid);
                SendClientMessage(playerid, COLOR_WHITE, "Bone County: Thank you for registering your citizenship!");
                SendClientMessage(playerid, COLOR_WHITE, "We now require you to fill out some basic identification!");
                SetPlayerCameraPos(playerid, 194.485778, 1103.993408, 16.347635);
                SetPlayerCameraLookAt(playerid, 194.485778, 1103.993408, 16.347635);
                SetPlayerVirtualWorld(playerid, 0);
                ShowDialog(playerid, 3, DIALOG_INFO, "Bone County Identification", "Are you a male or female?", "Male", "Female");
            }
            return 1;
        }
        case 2: //Login
        {
            if(!response) {
                SendClientMessage(playerid, COLOR_LIGHTRED, "    Come back soon...");
                Kick(playerid);
            }
            if(response) {
                if(udb_hash(inputtext) == PlayerInfo[playerid][Password])
                {
                    INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
                    SetPlayerHealth(playerid, PlayerInfo[playerid][sHealth]);
                    SetPlayerArmour(playerid, PlayerInfo[playerid][sArmor]);
                    ResetPlayerMoney(playerid);
                    GivePlayerMoney(playerid, PlayerInfo[playerid][Money]);
                    ClearScreen(playerid);
                    SendClientMessage(playerid, COLOR_WHITE, "SERVER: You've logged into Bone County Roleplay.");
                    SetSpawnInfo(playerid, 0, 0, 194.485778, 1103.993408, 16.347635, 30.403614, 0, 0, 0, 0, 0, 0);
                    SpawnPlayer(playerid);
                }
                else {
                    SendClientMessage(playerid, COLOR_LIGHTRED, "SERVER: Incorrect password. Kicked, please try again!");
                    Kick(playerid);
                }
            }
            return 1;
        }
        case 3: // Gender
        {
            if(response) {
                PlayerInfo[playerid][Gender] = 1; // Male
                ShowDialog(playerid, 4, DIALOG_INPUT, "Bone County Identification", "You identified yourself as a Male.\n\nNow how old are you?", "Enter", "");
                PlayerInfo[playerid][Skin] = 1;
                SetSpawnInfo(playerid, 0, 1, 194.485778, 1103.993408, 16.347635, 30.403614, 0, 0, 0, 0, 0, 0);
                }
            else {
                PlayerInfo[playerid][Gender] = 2; // Female
                ShowDialog(playerid, 4, DIALOG_INPUT, "Bone County Identification", "You identified yourself as a Female.\n\nNow how old are you?", "Enter", "");
                PlayerInfo[playerid][Skin] = 12;
                SetSpawnInfo(playerid, 0, 12, 194.485778, 1103.993408, 16.347635, 30.403614, 0, 0, 0, 0, 0, 0);
            }
        }
        case 4: // Age
        {
            new age = strval(inputtext);
            if(!strlen(inputtext)) return ShowDialog(playerid, 4, DIALOG_INPUT, "Bone County Identification", "Please tell us how old you are!", "Enter", "");
            //if(!IsNumeric(age)) return ShowDialog(playerid, 4, DIALOG_INPUT, "Fort Carson Identification", "Please tell us how old you are!", "Enter", "");
            if(age < 13 || age > 99) return ShowDialog(playerid, 4, DIALOG_INPUT, "Bone County Identification", "Please enter a realistic age (13-99)", "Enter", "");
            PlayerInfo[playerid][Age] = age;
            ShowDialog(playerid, 5, DIALOG_LIST, "Bone County Identification - Where are you from?", "America\nEurope\nAustralia\nAfrica\nRussia", "Okay", "");
        }
        case 5: // Origin
        {
            if(response)
            {
                switch(listitem)
                {
                    case 0: //America
                    {
                        PlayerInfo[playerid][Origin] = 1;
                    }
                    case 1: //Europe
                    {
                        PlayerInfo[playerid][Origin] = 2;
                    }
                    case 2: //Australia
                    {
                        PlayerInfo[playerid][Origin] = 3;
                    }
                    case 3: //Africa
                    {
                        PlayerInfo[playerid][Origin] = 4;
                    }
                    case 4: //Russia
                    {
                        PlayerInfo[playerid][Origin] = 5;
                    }
                }
                ShowDialog(playerid, 6, DIALOG_INFO, "Bone County Identifcation", "Thank you for identifying yourself.\n\nIf you require help, please use /help or /ask.\nIf you do not Roleplay, we will punish you.\n\nVisit our forums, www.gta-fcrp.com!", "Okay", "");
                gPlayerLoggedIn[playerid] = 1;
                SpawnPlayer(playerid);
             }
             else
             {
                ShowDialog(playerid, 5, DIALOG_LIST, "Bone County Identification - Where are you from?", "America\nEurope\nAustralia\nAfrica\nRussia", "Okay", "");
             }
        }
    }
    return 1;
}



pawn Code:
public OnPlayerDisconnect(playerid, reason)
{
    SavePlayer(playerid);
    return 1;
}


pawn Code:
public SavePlayer(playerid)
{
    new INI:File = INI_Open(UserPath(playerid));
    INI_SetTag(File,"data");
    new Float:sX, Float:sY, Float:sZ, Float:sA, Float:sH, Float:sAr;
    GetPlayerPos(playerid, sX, sY, sZ);
    GetPlayerFacingAngle(playerid, sA);
    GetPlayerHealth(playerid, sH);
    GetPlayerArmour(playerid, sAr);
    INI_WriteInt(File, "Password", PlayerInfo[playerid][Password]);
    INI_WriteInt(File, "Admin", PlayerInfo[playerid][Admin]);
    INI_WriteInt(File, "Origin", PlayerInfo[playerid][Origin]);
    INI_WriteInt(File, "Gender", PlayerInfo[playerid][Gender]);
    INI_WriteInt(File, "Age", PlayerInfo[playerid][Age]);
    INI_WriteFloat(File, "sPosX", sX);
    INI_WriteFloat(File, "sPosY", sY);
    INI_WriteFloat(File, "sPosZ", sZ);
    INI_WriteFloat(File, "sPosA", sA);
    INI_WriteFloat(File, "sHealth", sH);
    INI_WriteFloat(File, "sArmor", sAr);
    INI_WriteInt(File, "Money", PlayerInfo[playerid][Money]);
    INI_WriteInt(File, "BankBalance", PlayerInfo[playerid][BankBalance]);
    INI_WriteInt(File, "BankPin", PlayerInfo[playerid][BankPin]);
    INI_WriteInt(File, "Cellphone", PlayerInfo[playerid][Cellphone]);
    INI_WriteInt(File, "HouseID", PlayerInfo[playerid][HouseID]);
    INI_WriteInt(File, "CarID", PlayerInfo[playerid][CarID]);
    INI_WriteInt(File, "Gun1", 0);
    INI_WriteInt(File, "Gun2", 0);
    INI_WriteInt(File, "Gun3", 0);
    INI_WriteInt(File, "Gun4", 0);
    INI_WriteInt(File, "Gun5", 0);
    INI_WriteInt(File, "Gun6", 0);
    INI_WriteInt(File, "Gun7", 0);
    INI_WriteInt(File, "Gun8", 0);
    INI_WriteInt(File, "Gun9", 0);
    INI_WriteInt(File, "Gun10", 0);
    INI_WriteInt(File, "Gun11", 0);
    INI_WriteInt(File, "Gun12", 0);
    INI_WriteInt(File, "Gun13", 0);
    INI_WriteInt(File, "WTChannel", PlayerInfo[playerid][WTChannel]);
    INI_WriteInt(File, "Faction", PlayerInfo[playerid][Faction]);
    INI_WriteInt(File, "FLeader", PlayerInfo[playerid][FLeader]);
    INI_WriteInt(File, "Job", PlayerInfo[playerid][Job]);
    INI_WriteInt(File, "sInterior", GetPlayerInterior(playerid));
    INI_WriteInt(File, "sVW", GetPlayerVirtualWorld(playerid));
    INI_WriteInt(File, "Skin", PlayerInfo[playerid][Skin]);
    INI_WriteInt(File, "Muted", PlayerInfo[playerid][Muted]);
    INI_WriteInt(File, "nMute", PlayerInfo[playerid][nMute]);
    INI_WriteInt(File, "Helper", PlayerInfo[playerid][Helper]);
    INI_WriteInt(File, "Developer", PlayerInfo[playerid][Developer]);
    INI_WriteInt(File, "RentingID", PlayerInfo[playerid][RentingID]);
    INI_Close(File);
    gPlayerLoggedIn[playerid] = 0;
    return 1;
}


pawn Code:
/*Credits to Dracoblue*/
stock udb_hash(buf[]) {
    new length=strlen(buf);
    new s1 = 1;
    new s2 = 0;
    new n;
    for (n=0; n<length; n++)
    {
       s1 = (s1 + buf[n]) % 65521;
       s2 = (s2 + s1)     % 65521;
    }
    return (s2 << 16) + s1;
}
Reply
#2

Remove
pawn Code:
INI_WriteInt(File, "Password", PlayerInfo[playerid][Password]);
from your SavePlayer function. I've had this problem before.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)