Save/Load password (DINI)
#1

In the file there is the password "123" there is such a problem that when entering the password "123" it shows me the message that this is the wrong password. How to fix it?
Код:
#include <a_samp>
#include <dini>

#define COLOR_GREY 0xAFAFAFAA
#define COLOR_GREEN 0x33AA33AA
#define COLOR_ORANGE 0xFF9900AA
#define COLOR_RED 0xAA3333AA
#define COLOR_YELLOW 0xFFFF00AA

#define SERVER_USER_FILE "Users/%s.ini"

enum pInfo
{
    pAdminLevel,
    pCash,
    pScore,
}
new PlayerInfo[MAX_PLAYERS][pInfo];
new gPlayerLogged[MAX_PLAYERS];

public OnFilterScriptExit()
{
	return 1;
}

public OnPlayerConnect(playerid)
{
    gPlayerLogged[playerid] = 0;
    new name[MAX_PLAYER_NAME], file[256];
    GetPlayerName(playerid, name, sizeof(name));
    format(file, sizeof(file), SERVER_USER_FILE, name);
    if (!dini_Exists(file))
    {
        ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "Hi your not registered", "Welcome, your not registered mate, input your registration pw below", "Register", "Leave");
    }
    if(fexist(file))
    {
        ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "Hi your registered", "Fucken awesome mate, your registered :D. Inpute your pw below", "Login", "Leave");
    }
	return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    new name[MAX_PLAYER_NAME], file[256];
    GetPlayerName(playerid, name, sizeof(name));
    format(file, sizeof(file), SERVER_USER_FILE, name);
    if(gPlayerLogged[playerid] == 1)
    {
        dini_IntSet(file, "Score", PlayerInfo[playerid][pScore]);
        dini_IntSet(file, "Money", PlayerInfo[playerid][pCash]);
        dini_IntSet(file, "AdminLevel",PlayerInfo[playerid][pAdminLevel]);
    }
    gPlayerLogged[playerid] = 0;
	return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if (dialogid == 1)
    {
        new name[MAX_PLAYER_NAME], file[256], string[128];
        GetPlayerName(playerid, name, sizeof(name));
        format(file, sizeof(file), SERVER_USER_FILE, name);
        if(!response) return Kick(playerid);
        if(strlen(inputtext) <= 2 || strlen(inputtext) >= 21)
			return ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "Hi your not registered", "Welcome, your not registered mate, input your registration pw below", "Register", "Leave");
        dini_Create(file);
        dini_Set(file, "Password", inputtext);
        dini_IntSet(file, "AdminLevel",PlayerInfo[playerid][pAdminLevel] = 0);
        dini_IntSet(file, "Money",PlayerInfo[playerid][pCash] = 0);
        dini_IntSet(file, "Score",PlayerInfo[playerid][pScore] = 0);
        format(string, 128, "[SYSTEM]: You succesfully registered the nickname %s with password %s, you have been auto logged in.", name, inputtext);
        SendClientMessage(playerid, COLOR_YELLOW, string);
        gPlayerLogged[playerid] = 1;
    }
    if (dialogid == 2)
    {
        new name[MAX_PLAYER_NAME], file[256];
        GetPlayerName(playerid, name, sizeof(name));
        format(file, sizeof(file), SERVER_USER_FILE, name);
        if(!response) return Kick(playerid);
        if(!strlen(inputtext)) return ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "Hi your registered", "Fucken awesome mate, your registered :D. Inpute your pw below", "Login", "Leave");
        if(!strlen(inputtext))
		{
            SendClientMessage(playerid, COLOR_RED, "Wrong PW sir.");
            ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "Hi your registered", "Fucken awesome mate, your registered :D. Inpute your pw below", "Login", "Leave");
        }
        else
        {
            gPlayerLogged[playerid] = 1;
            PlayerInfo[playerid][pAdminLevel] = dini_Int(file, "AdminLevel");
            SetPlayerScore(playerid, PlayerInfo[playerid][pScore]);
            GivePlayerMoney(playerid, dini_Int(file, "Money")-GetPlayerMoney(playerid));
            SendClientMessage(playerid,COLOR_RED, "[SYSTEM]: Successfully logged in!");
        }
    }
	return 1;
}
Reply
#2

well if u want a truth, it's not an actually login system.
you can use this thread, there's a little tutorial of register/login - https://sampforum.blast.hk/showthread.php?tid=47131
Reply
#3

Quote:
Originally Posted by Mugala
Посмотреть сообщение
well if u want a truth, it's not an actually login system.
you can use this thread, there's a little tutorial of register/login - https://sampforum.blast.hk/showthread.php?tid=47131
Lol not a register system? You should visit the doctor for sure.
It may be coded badly But that doesnt mean it isnt a register system.
Reply
#4

Quote:
Originally Posted by jasperschellekens
Посмотреть сообщение
Lol not a register system? You should visit the doctor for sure.
It may be coded badly But that doesnt mean it isnt a register system.
I said login system, not a register, who needs a doctor now?
his register system looks good, but in login, he doesn't even have a dini used to get a password for user.
Reply
#5

PHP код:
if(!strlen(inputtext)) 
This is not how you check password! Use this function: https://sampwiki.blast.hk/wiki/Strcmp
Reply
#6

This:
PHP код:
 if(!strlen(inputtext)) return ShowPlayerDialog(playerid2DIALOG_STYLE_INPUT"Hi your registered""Fucken awesome mate, your registered :D. Inpute your pw below""Login""Leave");
        if(!
strlen(inputtext)) 
Is not how pawn works, doing a statement that returns a value then the same statement after it, the 2nd one will NEVER get called.
Second of all, the login part doesn't even check for the password, where is the
Код:
if(dini_Int(file,"PASS") == inputtext) .. login /else return SCM(wrong pw... //etc
Read that and edit your code.

EDIT: or use strcmp like what gammix said, both works.
Reply
#7

It works. Thanks!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)