I can login with wrong password
#1

Hello,
I'm creating a CnR gamemode in Y_ini
I follow Newbienoob's Register/Login tutorial
it register fine, but when i login with wrong password
it logs in. How to fix this problem?

Code

pawn Код:
/*******************************************************************************

                    Extreme Hot Cops'n'Robbers (0.3e)
                          script by Romel
                             0.3e script
                             
                              Credits:

                               ******
                                Zeex
                              DracoBlue
                             newbienoob
                               Romel
                             
*******************************************************************************/


//Includes

#include <a_samp>
#include <zcmd>
#include <sscanf2>
#include <YSI\y_ini>

//Whirlpool native

native WP_Hash(buffer[], len, const str[]); //credits to ******

//prototype forward

forward loadaccount_user(playerid, name[], value[]);

//enum

enum PlayerInfo
{
    pLog,
    Pass[129],
    pAdmin,
    pVip,
    pClass,
    pSkin,
    pMoney,
    pScore,
    pKills,
    pDeaths
};
new pInfo[MAX_PLAYERS][PlayerInfo];

//Defines

#define                 white                           "{FFFFFF}"
#define                 red                             "{FF002B}"
#define                 blue                            "{A1C2FF}"
#define                 green                           "{3DE3B1}"
#define                 yellow                          "{FAF623}"
#define                 orange                          "{F2C80C}"

#define                 COLOR_GREY                      0xAFAFAFAA
#define                 COLOR_PURPLE                    0xD526D9FF
#define                 COLOR_WHITE                     0xFFFFFFFF
#define                 COLOR_ORANGE                    0xFF8000FF
#define                 COLOR_RED                       0xFF0000FF
#define                 COLOR_YELLOW                    0xFFFF00FF
#define                 COLOR_GREEN                     0x008000FF
#define                 COLOR_LIGHTGREEN                0x00FF00FF
#define                 COLOR_BLUE                      0x0080FFFF
#define                 COLOR_PINK                      0xFF80FFFF
#define                 COLOR_LIME                      0x00FF00FF
#define                 COLOR_LIGHTBLUE                 0x33CCFFAA

#define                 Data                            "Database/Users/%s.ini"

#define                 DIALOG_REGISTER                 1000
#define                 DIALOG_LOGIN                    1001
#define                 DIALOG_INFO                     1002

#if defined GAMEMODE

//==============================================================================

#else

main()
{
    print("\n========================================");
    print("\n");
    print("  Extreme Hot Cops'n'Robbers (0.3e)  ");
    print("          script by Romel        ");
    print("         Loaded all scripts!       ");
    print("\n");
    print("========================================\n");

}

#endif

public loadaccount_user(playerid, name[], value[])
{
    INI_String("Password", pInfo[playerid][Pass], 129);
    INI_Int("Class", pInfo[playerid][pClass]);
    INI_Int("Skin", pInfo[playerid][pSkin]);
    INI_Int("Admin", pInfo[playerid][pAdmin]);
    INI_Int("VIP", pInfo[playerid][pVip]);
    INI_Int("Money", pInfo[playerid][pMoney]);
    INI_Int("Score", pInfo[playerid][pScore]);
    INI_Int("Kills", pInfo[playerid][pKills]);
    INI_Int("Deaths", pInfo[playerid][pDeaths]);
    return 1;
}

public OnGameModeInit()
{
    SetGameModeText("Cops and Robbers");
    SendRconCommand("mapname San Fierro");
    AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
    return 1;
}

public OnGameModeExit()
{
    print("\n========================================");
    print("\n");
    print("  Extreme Hot Cops'n'Robbers (0.3e)  ");
    print("          script by Romel        ");
    print("         Closing all scripts!       ");
    print("\n");
    print("========================================\n");
    return 1;
}

public OnPlayerRequestClass(playerid, classid)
{
    SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
    SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
    SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
    pInfo[playerid][pClass] = classid;
    return 1;
}

public OnPlayerConnect(playerid)
{
    new str[128], formatit[356];
    format(str, sizeof(str), "CONNECT: %s(%d) has connect to Extreme Hot Cops'n'Robbers", GetName(playerid));
    SendClientMessageToAll(COLOR_PURPLE, str);

    SendClientMessage(playerid, COLOR_YELLOW, "Welcome to Extreme Hot Cops'n'Robbers");
    SendClientMessage(playerid, COLOR_LIME, "You are now going to Register proccess...");
    SendClientMessage(playerid, COLOR_WHITE, "Have fun playing on Extreme Hot Cops'n'Robbers");
    SendClientMessage(playerid, COLOR_YELLOW, "/help if you need anything...");

    pInfo[playerid][pLog] = 0;
    pInfo[playerid][pClass] = 0;
    pInfo[playerid][pSkin] = 0;
    pInfo[playerid][pAdmin] = 0;
    pInfo[playerid][pVip] = 0;
    pInfo[playerid][pMoney] = 0;
    GivePlayerMoney(playerid, pInfo[playerid][pMoney]);
    pInfo[playerid][pScore] = 0;
    SetPlayerScore(playerid, pInfo[playerid][pScore]);
    pInfo[playerid][pKills] = 0;
    pInfo[playerid][pDeaths] = 0;

    if(fexist(PathData(playerid)))
    {
        INI_ParseFile(PathData(playerid), "loadaccount_%s", .bExtra = true, .extra = playerid);
        format(formatit, sizeof(formatit), ""white"Welcome back, %s.\nThis name is registered.\nPlease Insert your password to login'n'play", GetName(playerid));
        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, ""white"Login", formatit, "Login", "Quit");
    }
    else
    {
        format(formatit, sizeof(formatit), ""white"Welcome to EHCnR, %s.\nThis name is not registered.\nEnter your own password\nto registered this name", GetName(playerid));
        ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, ""white"Register", formatit, "Register", "Quit");
    }
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    if(fexist(PathData(playerid)) && pInfo[playerid][pLog] == 1)
    {
        new INI:file = INI_Open(PathData(playerid));
        INI_SetTag(file, "account");
        INI_WriteInt(file, "Class", pInfo[playerid][pClass]);
        INI_WriteInt(file, "Skin", GetPlayerSkin(playerid));
        INI_WriteInt(file, "Admin", pInfo[playerid][pAdmin]);
        INI_WriteInt(file, "VIP", pInfo[playerid][pVip]);
        INI_WriteInt(file, "Money", GetPlayerMoney(playerid));
        INI_WriteInt(file, "Score", GetPlayerScore(playerid));
        INI_WriteInt(file, "Kills", pInfo[playerid][pKills]);
        INI_WriteInt(file, "Deaths",pInfo[playerid][pDeaths]);
        INI_Close(file);
        pInfo[playerid][pLog] = 0;
    }
    return 1;
}

public OnPlayerSpawn(playerid)
{
    return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
    pInfo[killerid][pKills]++;
    pInfo[playerid][pDeaths]++;
    GivePlayerMoney(killerid, 50000);
    GivePlayerMoney(playerid, -50000);
    SetPlayerScore(playerid, GetPlayerScore(playerid) + 1);
    SetPlayerScore(playerid, GetPlayerScore(playerid) - 1);
    return 1;
}

public OnVehicleSpawn(vehicleid)
{
    return 1;
}

public OnVehicleDeath(vehicleid, killerid)
{
    return 1;
}

public OnPlayerText(playerid, text[])
{
    return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/mycommand", cmdtext, true, 10) == 0)
    {
        // Do something here
        return 1;
    }
    return 0;
}

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    return 1;
}

public OnPlayerExitVehicle(playerid, vehicleid)
{
    return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    return 1;
}

public OnPlayerEnterCheckpoint(playerid)
{
    return 1;
}

public OnPlayerLeaveCheckpoint(playerid)
{
    return 1;
}

public OnPlayerEnterRaceCheckpoint(playerid)
{
    return 1;
}

public OnPlayerLeaveRaceCheckpoint(playerid)
{
    return 1;
}

public OnRconCommand(cmd[])
{
    return 1;
}

public OnPlayerRequestSpawn(playerid)
{
    if(pInfo[playerid][pLog] == 0 || !fexist(PathData(playerid)))
    {
        SendClientMessage(playerid, COLOR_RED, "You cannot spawn, Please register or login first!");
        return 0;
    }
    return 1;
}

public OnObjectMoved(objectid)
{
    return 1;
}

public OnPlayerObjectMoved(playerid, objectid)
{
    return 1;
}

public OnPlayerPickUpPickup(playerid, pickupid)
{
    return 1;
}

public OnVehicleMod(playerid, vehicleid, componentid)
{
    return 1;
}

public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
{
    return 1;
}

public OnVehicleRespray(playerid, vehicleid, color1, color2)
{
    return 1;
}

public OnPlayerSelectedMenuRow(playerid, row)
{
    return 1;
}

public OnPlayerExitedMenu(playerid)
{
    return 1;
}

public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
{
    return 1;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    return 1;
}

public OnRconLoginAttempt(ip[], password[], success)
{
    return 1;
}

public OnPlayerUpdate(playerid)
{
    return 1;
}

public OnPlayerStreamIn(playerid, forplayerid)
{
    return 1;
}

public OnPlayerStreamOut(playerid, forplayerid)
{
    return 1;
}

public OnVehicleStreamIn(vehicleid, forplayerid)
{
    return 1;
}

public OnVehicleStreamOut(vehicleid, forplayerid)
{
    return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    new str[128], formatit[356], hash[129];
    if(dialogid == DIALOG_REGISTER)
    {
        if(!response)
        {
            format(str, sizeof(str), "KICK: %s(%d) has been kicked for Not Registering instead Quiting", GetName(playerid), playerid);
            SendClientMessageToAll(COLOR_RED, str);
            SendClientMessage(playerid, COLOR_RED, "KICK: You choose to Quit instead of Registering");
            Kick(playerid);
            return 1;
        }
        else if(response)
        {
            if(!strlen(inputtext))
            {
                format(formatit, sizeof(formatit), ""white"Welcome to EHCnR, %s.\nThis name is not registered.\nEnter your own password\nto registered this name\n"red"Try again error occur!", GetName(playerid));
                ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, ""white"Register", formatit, "Register", "Quit");
                return 1;
            }
            WP_Hash(hash, sizeof(hash), inputtext);
            pInfo[playerid][pMoney] = 50000;
            GivePlayerMoney(playerid, pInfo[playerid][pMoney]);
            pInfo[playerid][pScore] = 1;
            SetPlayerScore(playerid, pInfo[playerid][pScore]);
            new INI:file = INI_Open(PathData(playerid));
            INI_SetTag(file, "account");
            INI_WriteString(file, "Password", hash);
            INI_WriteInt(file, "Class", pInfo[playerid][pClass]);
            INI_WriteInt(file, "Skin", pInfo[playerid][pSkin]);
            INI_WriteInt(file, "Admin", pInfo[playerid][pAdmin]);
            INI_WriteInt(file, "VIP", pInfo[playerid][pVip]);
            INI_WriteInt(file, "Money", pInfo[playerid][pMoney]);
            INI_WriteInt(file, "Score", pInfo[playerid][pScore]);
            INI_WriteInt(file, "Kills", pInfo[playerid][pKills]);
            INI_WriteInt(file, "Deaths", pInfo[playerid][pDeaths]);
            INI_Close(file);
            format(str, sizeof(str), "You've registered your name with password '%s', Now you are taking to Rules processing...", inputtext);
            SendClientMessage(playerid, COLOR_LIME, str);
            pInfo[playerid][pLog] = 1;
            return 1;
        }
    }
    if(dialogid == DIALOG_LOGIN)
    {
        if(!response)
        {
            format(str, sizeof(str), "KICK: %s(%d) has been kicked for Not Logging in instead Quiting", GetName(playerid), playerid);
            SendClientMessageToAll(COLOR_RED, str);
            SendClientMessage(playerid, COLOR_RED, "KICK: You choose to Quit instead of Logging in");
            Kick(playerid);
            return 1;
        }
        else if(response)
        {
            WP_Hash(hash, sizeof(hash),inputtext);
            if(strcmp(pInfo[playerid][Pass], hash, true) == 0)
            {
                INI_ParseFile(PathData(playerid), "loadaccount_%s", .bExtra = true, .extra = playerid);
                SetPlayerScore(playerid, pInfo[playerid][pScore]);
                GivePlayerMoney(playerid, pInfo[playerid][pMoney]);
                SendClientMessage(playerid, COLOR_LIME, "Welcome back!, You've successfully logged in.");
                SendClientMessage(playerid, -1, "Current life...");
                format(formatit, sizeof(formatit), ""white"Your name account status:\n\nAdminLvl: %i\nVipLvl: %i\nMoney: $%i\nScore: %i\nKills: %i\nDeaths: %i", pInfo[playerid][pAdmin], pInfo[playerid][pVip], pInfo[playerid][pMoney], pInfo[playerid][pScore], pInfo[playerid][pKills], pInfo[playerid][pDeaths]);
                ShowPlayerDialog(playerid, DIALOG_INFO, DIALOG_STYLE_MSGBOX, ""white"Status:", formatit, "Ok", "");
                pInfo[playerid][pLog] = 1;
            }
            else
            {
                format(formatit, sizeof(formatit), ""white"Welcome back, %s.\nThis name is registered.\nPlease Insert your password to login'n'play\n"red"Try again error occur!", GetName(playerid));
                ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, ""white"Login", formatit, "Login", "Quit");
                return 1;
            }
        }
    }
    return 1;
}

public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
    return 1;
}

//==============================================================================

stock PathData(playerid)
{
    new str[128];
    format(str, sizeof(str), Data, GetName(playerid));
    return str;
}

stock GetName(playerid)
{
    new pName[MAX_PLAYER_NAME];
    GetPlayerName(playerid, pName, sizeof(pName));
    return pName;
}
Reply
#2

pawn Код:
if(strcmp(pInfo[playerid][Pass], hash, true) == 0)
There is a chance that this line fails, because one of the strings is empty.
Reply
#3

Well the line Password in the .ini is not empty.
Plus i make sure that Pass is String
Reply
#4

bump
Reply
#5

Why don't you have a selection for a incorrect password?
---

Sleepy it's 1am.
Reply
#6

You are to sleepy today kiddo.
I have code for that here it is sleepy kid

pawn Код:
WP_Hash(hash, sizeof(hash),inputtext);
            if(strcmp(pInfo[playerid][Pass], hash, true) == 0)
            {
                INI_ParseFile(PathData(playerid), "loadaccount_%s", .bExtra = true, .extra = playerid);
                SetPlayerScore(playerid, pInfo[playerid][pScore]);
                GivePlayerMoney(playerid, pInfo[playerid][pMoney]);
                SendClientMessage(playerid, COLOR_LIME, "Welcome back!, You've successfully logged in.");
                SendClientMessage(playerid, -1, "Current life...");
                format(formatit, sizeof(formatit), ""white"Your name account status:\n\nAdminLvl: %i\nVipLvl: %i\nMoney: $%i\nScore: %i\nKills: %i\nDeaths: %i", pInfo[playerid][pAdmin], pInfo[playerid][pVip], pInfo[playerid][pMoney], pInfo[playerid][pScore], pInfo[playerid][pKills], pInfo[playerid][pDeaths]);
                ShowPlayerDialog(playerid, DIALOG_INFO, DIALOG_STYLE_MSGBOX, ""white"Status:", formatit, "Ok", "");
                pInfo[playerid][pLog] = 1;
            }
            else
            {
                format(formatit, sizeof(formatit), ""white"Welcome back, %s.\nThis name is registered.\nPlease Insert your password to login'n'play\n"red"Try again error occur!", GetName(playerid));
                ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, ""white"Login", formatit, "Login", "Quit");
                return 1;
            }
Reply
#7

I think wups is right.
The string is empty.
Also the Admin/Vip/Score/Money/Kills/Deaths/Skin/Class return as 0 after i quit.
and this maybe the reason why my server cannot detect if the password is correct or not..
Reply
#8

OnPlayerDisconnect, it doesn't write a password.

o.e or im just sleepy
Reply
#9

You don't need to write the password onplayerdisconnect. because it was already written when player registers.
Reply
#10

I'm sorry it's 2:47am :'[ ; sleepy

Код:
        else if(response)
        {
            WP_Hash(hash, sizeof(hash),inputtext);
            if(strcmp(pInfo[playerid][Pass], hash, true) == 0)
            {
                INI_ParseFile(PathData(playerid), "loadaccount_%s", .bExtra = true, .extra = playerid);
                SetPlayerScore(playerid, pInfo[playerid][pScore]);
                GivePlayerMoney(playerid, pInfo[playerid][pMoney]);
                SendClientMessage(playerid, COLOR_LIME, "Welcome back!, You've successfully logged in.");
                SendClientMessage(playerid, -1, "Current life...");
                format(formatit, sizeof(formatit), ""white"Your name account status:\n\nAdminLvl: %i\nVipLvl: %i\nMoney: $%i\nScore: %i\nKills: %i\nDeaths: %i", pInfo[playerid][pAdmin], pInfo[playerid][pVip], pInfo[playerid][pMoney], pInfo[playerid][pScore], pInfo[playerid][pKills], pInfo[playerid][pDeaths]);
                ShowPlayerDialog(playerid, DIALOG_INFO, DIALOG_STYLE_MSGBOX, ""white"Status:", formatit, "Ok", "");
                pInfo[playerid][pLog] = 1;
            }
            else
            {
Why do you have the direct value to "0"

Код:
    
          WP_Hash(hash, sizeof(hash),inputtext);
            if(strcmp(pInfo[playerid][Pass], hash, true) == 0)
I feel retarded I think i should go to sleep v-v
---

I'm going to sleep sorry. I don't even know if I helped or not, i'm just to sleepy sorry.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)