Registration/Logging system wrong?
#1

Hi, I was making a system for Registration/Logging, I register and all, but to the logging pulled me a mistake, I try to log and happens to me that is incorrect password when is fact is correct, I'm new in Pawno perhaps is my littlw knowledge, I thanks you for help. (Sorry my english).

Код:
#include <YSI\y_ini>

#pragma tabsize 0

#define PATH "/Usuarios/%s.ini"

#define DIALOG_REGISTER 1
#define DIALOG_LOGIN 2
#define DIALOG_SUCCESS_1 3
#define DIALOG_SUCCESS_2 4

enum pInfo
{
    pPassword,
    pMoney,
    pAdmin,
    pKills,
    pDeaths
}
new PlayerInfo[MAX_PLAYERS][pInfo];

forward LoadUser_data(playerid,name[],value[]);
public LoadUser_data(playerid,name[],value[])
{
    INI_Int("Contraseсa",PlayerInfo[playerid][pPassword]);
    INI_Int("Dinero",PlayerInfo[playerid][pMoney]);
    INI_Int("Admin",PlayerInfo[playerid][pAdmin]);
    INI_Int("Asesinatos",PlayerInfo[playerid][pKills]);
    INI_Int("Muertes",PlayerInfo[playerid][pDeaths]);
    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;
}

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;
}

public OnPlayerConnect(playerid)
{
    if(fexist(UserPath(playerid)))
    {
        INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD,"{FF8000}:: || Logeo || ::","{FFFFFF}Tu cuenta esta registrada, porfavor escribe tu contraseсa.","Login","");
    }
    else
    {
        ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT,"{FF8000}:: || Registro || ::","{FFFFFF}Tu cuenta no esta registrada, porfavor escribe una nueva contraseсa para registrarla.","Register","");
        return 1;
    }
	return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    new INI:File = INI_Open(UserPath(playerid));
    INI_SetTag(File,"data");
    INI_WriteInt(File,"Money",GetPlayerMoney(playerid));
    INI_WriteInt(File,"Admin",PlayerInfo[playerid][pAdmin]);
    INI_WriteInt(File,"Kills",PlayerInfo[playerid][pKills]);
    INI_WriteInt(File,"Deaths",PlayerInfo[playerid][pDeaths]);
    INI_Close(File);
    GangZoneHideForPlayer(playerid,gangzone);
	return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch( dialogid )
    {
        case DIALOG_REGISTER:
        {
            if(response)
            {
                if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "{FF8000}:: || Registro || ::","{FFFFFF}Tu cuenta no esta registrada, porfavor escribe una nueva contraseсa para registrarla","Register","");
                new INI:File = INI_Open(UserPath(playerid));
                INI_SetTag(File,"data");
                INI_WriteInt(File,"Password",udb_hash(inputtext));
                INI_WriteInt(File,"Money",0);
                INI_WriteInt(File,"Admin",0);
                INI_WriteInt(File,"Kills",0);
                INI_WriteInt(File,"Deaths",0);
                INI_Close(File);

                SetSpawnInfo(playerid, 0, 0, 1958.33, 1343.12, 15.36, 269.15, 0, 0, 0, 0, 0, 0);
                SpawnPlayer(playerid);
                SendClientMessage(playerid, COLOR_CHARTREUSE, "[<!>] Tu cuenta se ha registrado correctamente.");
            }
        }

        case DIALOG_LOGIN:
        {
            if( response )
            {
                if(udb_hash(inputtext) == PlayerInfo[playerid][pPassword])
                {
                    INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
                    GivePlayerMoney(playerid, PlayerInfo[playerid][pMoney]);
                    SendClientMessage(playerid, COLOR_CHARTREUSE, "[<!>] Has logeado correctamente.");
                }
                else
                {
                    ShowPlayerDialog(playerid, DIALOG_SUCCESS_2, DIALOG_STYLE_INPUT,"{FF8000}:: || Logeo || ::","{FF0000}Contraseсa incorrecta. \n{FFFFFF}Escribe tu contraseсa para logearte.","Login","");
                    INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
                    GivePlayerMoney(playerid, PlayerInfo[playerid][pMoney]);
                    SendClientMessage(playerid, COLOR_CHARTREUSE, "[<!>] Has logeado correctamente.");
                }
                return 1;
            }
        }
    }
    return 1;
}
Reply
#2

This should be the same name
PHP код:
forward LoadUser_data(playerid,name[],value[]);
public 
LoadUser_data(playerid,name[],value[])
{
    
INI_Int("Contraseсa",PlayerInfo[playerid][pPassword]);
    
INI_Int("Dinero",PlayerInfo[playerid][pMoney]);
    
INI_Int("Admin",PlayerInfo[playerid][pAdmin]);
    
INI_Int("Asesinatos",PlayerInfo[playerid][pKills]);
    
INI_Int("Muertes",PlayerInfo[playerid][pDeaths]);
    return 
1;

PHP код:
    new INI:File INI_Open(UserPath(playerid));
    
INI_SetTag(File,"data");
    
INI_WriteInt(File,"Money",GetPlayerMoney(playerid));
    
INI_WriteInt(File,"Admin",PlayerInfo[playerid][pAdmin]);
    
INI_WriteInt(File,"Kills",PlayerInfo[playerid][pKills]);
    
INI_WriteInt(File,"Deaths",PlayerInfo[playerid][pDeaths]);
    
INI_Close(File); 
Reply
#3

Can I just point out....

dont use udb_hash, its unsecure and easy to crack passwords...

use whirlpool or some other hashing system
Reply
#4

Quote:
Originally Posted by Dayrion
Посмотреть сообщение
This should be the same name
PHP код:
forward LoadUser_data(playerid,name[],value[]);
public 
LoadUser_data(playerid,name[],value[])
{
    
INI_Int("Contraseсa",PlayerInfo[playerid][pPassword]);
    
INI_Int("Dinero",PlayerInfo[playerid][pMoney]);
    
INI_Int("Admin",PlayerInfo[playerid][pAdmin]);
    
INI_Int("Asesinatos",PlayerInfo[playerid][pKills]);
    
INI_Int("Muertes",PlayerInfo[playerid][pDeaths]);
    return 
1;

PHP код:
    new INI:File INI_Open(UserPath(playerid));
    
INI_SetTag(File,"data");
    
INI_WriteInt(File,"Money",GetPlayerMoney(playerid));
    
INI_WriteInt(File,"Admin",PlayerInfo[playerid][pAdmin]);
    
INI_WriteInt(File,"Kills",PlayerInfo[playerid][pKills]);
    
INI_WriteInt(File,"Deaths",PlayerInfo[playerid][pDeaths]);
    
INI_Close(File); 
Still not working
Reply
#5

Change :
PHP код:
if(udb_hash(inputtext) == PlayerInfo[playerid][pPassword]) 
to
PHP код:
if(!strcmp((udb_hash(inputtext), PlayerInfo[playerid][pPassword]))) 
Reply
#6

Код:
warning 202: number of arguments does not match definition
Reply
#7

Quote:
Originally Posted by Dayrion
Посмотреть сообщение
Change :
PHP код:
if(udb_hash(inputtext) == PlayerInfo[playerid][pPassword]) 
to
PHP код:
if(!strcmp((udb_hash(inputtext), PlayerInfo[playerid][pPassword]))) 
The password is a variable.

Anyways, you got that at the register dialog:
Код:
                if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "{FF8000}:: || Registro || ::","{FFFFFF}Tu cuenta no esta registrada, porfavor escribe una nueva contraseсa para registrarla","Register","");
                new INI:File = INI_Open(UserPath(playerid));
                INI_SetTag(File,"data");
                INI_WriteInt(File,"Password",udb_hash(inputtext));
                INI_WriteInt(File,"Money",0);
                INI_WriteInt(File,"Admin",0);
                INI_WriteInt(File,"Kills",0);
                INI_WriteInt(File,"Deaths",0);
                INI_Close(File);
As you can see these are in English, like Password, Money, etc, but when you load an account you are trying to get a value from the non-English ones. Like for example when you register money is stored in "Money", but when you load the account, you are trying to get the value from "Dinero". Same with OnPlayerDisconnect they are in English there.

EDIT: I just noticed that Dayrion already said that, but I see you got с in a word there, can it even write and read these kind of characters?
Reply
#8

Don't use udb_hash - it is not secure! It literally requires you to read an extra tutorial (most of them are designed to make copy-pasting easier anyway, so not much reading there) to secure your passwords correctly. (Hint: SHA256 (built-in) or Whirlpool (plugin))
Reply
#9

Thanks, it works :3
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)