Incorrect Password.
#1

i saw a tutorial and made register login system for my new server all done no warnings and errors are durring compiling..
when i register it workds fine but when i relog and enter pass it says incorrect pass and im 100% sure im entering the correct password.

pawn Код:
#include <a_samp>
#include <sscanf2>
#include <foreach>
#include <YSI\y_ini>

#define COLOR_ERROR 0xFF0000FF

#define DIALOG_REGISTER 1
#define DIALOG_LOGIN 2
#define PATH "/Users/%s.ini"

enum pInfo
{
    pPass,
    pRegistered
}
new PlayerInfo[MAX_PLAYERS][pInfo];

forward LoadUser_data(playerid,name[],value[]);
public  LoadUser_data(playerid,name[],value[])
{
    INI_Int("Password",PlayerInfo[playerid][pPass]);
    INI_Int("Registered",PlayerInfo[playerid][pRegistered]);
    return 1;
}

stock UserPath(playerid)
{
    new string[128],name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,sizeof(name));
    format(string,sizeof(string),PATH,name);
    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;
}

main() {}
public OnGameModeInit()
{
    SetGameModeText("Cops And Robbers");
    AddPlayerClass(1, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
    return 1;
}

public OnGameModeExit()
{
    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);
    return 1;
}

public OnPlayerConnect(playerid)
{
    if(fexist(UserPath(playerid)))
    {
        INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
       
        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,"Login","Type your password below to login.","Login","Quit");
    }
    else
    {
        ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT,"Registering...","Type your password below to register a new account.","Register","Quit");
    }
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
        SavePlayerStats(playerid);
    return 1;
}

stock SavePlayerStats(playerid)
{
    new INI:File = INI_Open(UserPath(playerid));
    INI_SetTag(File,"DATA");
    INI_WriteInt(File,"Registered",PlayerInfo[playerid][pRegistered]);
    INI_Close(File);
}

public OnPlayerSpawn(playerid)
{
    return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
    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)
{
    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[])
{
    switch( dialogid )
    {
        case DIALOG_REGISTER:
        {
            if (!response)
            {
                Kick(playerid);
                return 1;
            }
           
            if (response)
            {
                if(strlen(inputtext) < 6)
                {
                SendClientMessage(playerid, COLOR_ERROR, "Your Password Is Too Short, Enter a Long Password.");
                ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Registering...","You have entered an invalid password.\nType your password below to register a new account.","Register","Quit");
                return 1;
                }

                if(strlen(inputtext) > 12)
                {
                SendClientMessage(playerid, COLOR_ERROR, "Your Password Is Too Long, Enter a Short Password.");
                ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Registering...","You have entered an invalid password.\nType your password below to register a new account.","Register","Quit");
                return 1;
                }

                new INI:File = INI_Open(UserPath(playerid));
                INI_SetTag(File,"DATA");
                INI_WriteInt(File,"Password",udb_hash(inputtext));
                INI_WriteInt(File,"Registered",1);
                INI_Close(File);
            }
        }

        case DIALOG_LOGIN:
        {
            if (!response)
            {
            Kick(playerid);
            return 1;
            }
           
            if (response)
            {
                if(udb_hash(inputtext) == PlayerInfo[playerid][pPass] && strlen(inputtext) > 0)
                {
                    INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
                    SendClientMessage(playerid, -1, "You Have Been Succesfully Logged In.");
                }
                else
                {
                    ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,"Login","You have entered an incorrect password.\nType your password below to login.","Login","Quit");
                }
                return 1;
            }
        }
    }
    return 1;
}

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

Always use debugs on this cases, printf

Try to debug both the hashed inputtext and player password, if they are not the same it means that something wrong.

Also, You need to use strcmp in comparing strings not == you're not comparing integers.

pawn Код:
if (response)
            {
                if( !strcmp(udb_hash(inputtext) ) , PlayerInfo[playerid][pPass] ) && strlen(inputtext) > 0)
                {
                    INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
                    SendClientMessage(playerid, -1, "You Have Been Succesfully Logged In.");
                }
                else
                {
                    ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,"Login","You have entered an incorrect password.\nType your password below to login.","Login","Quit");
                }
                return 1;
            }
Reply
#3

i used your code but...

pawn Код:
D:\Danish\New Cops & Robbers\gamemodes\CNR.pwn(314) : error 035: argument type mismatch (argument 1)
D:\Danish\New Cops & Robbers\gamemodes\CNR.pwn(314) : error 029: invalid expression, assumed zero
D:\Danish\New Cops & Robbers\gamemodes\CNR.pwn(314) : warning 215: expression has no effect
D:\Danish\New Cops & Robbers\gamemodes\CNR.pwn(314) : error 001: expected token: ";", but found ")"
D:\Danish\New Cops & Robbers\gamemodes\CNR.pwn(314) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664          Copyright (c) 1997-2006, ITB CompuPhase


4 Errors.
Reply
#4

Ah sorry update it to this one:

pawn Код:
if (response)
            {
                if( !strcmp( udb_hash(inputtext) , PlayerInfo[playerid][pPass] ) && strlen(inputtext) > 0 )
                {
                    INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
                    SendClientMessage(playerid, -1, "You Have Been Succesfully Logged In.");
                }
                else
                {
                    ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,"Login","You have entered an incorrect password.\nType your password below to login.","Login","Quit");
                }
                return 1;
            }
Reply
#5

again error man
pawn Код:
D:\Danish\New Cops & Robbers\gamemodes\CNR.pwn(328) : error 035: argument type mismatch (argument 1)
Reply
#6

Well, i guess it seems that the problem is not in the same line,
old: D:\Danish\New Cops & Robbers\gamemodes\CNR.pwn( 314 ) : error 035: argument type mismatch (argument 1)
new: D:\Danish\New Cops & Robbers\gamemodes\CNR.pwn( 328 ) : error 035: argument type mismatch (argument 1)

So, please show me that line? ( if you don't know how: Control + G and 328 ).
Reply
#7

its same line
Reply
#8

udb_hash returns an integer rather than a string. Whirlpool is a much better alternative than udb_hash... I suggest you start using it.

INI_SetTag(..., "DATA");

Try changing 'DATA' to 'data', see if anything changes.
Reply
#9

Well, i took a look over the codes and its poorly made, and not recommended to use, because he is using :
enum pInfo
{
pPass,
pRegistered
}

INI_Int("Password",PlayerInfo[playerid][pPass]);
He loads the password as an integer ( like 12313 ) numbers only, not as a string thats why he used to compare them like this, i don't know if there is some more bugs so its more recommended to use this one:

https://sampforum.blast.hk/showthread.php?tid=273088
Reply
#10

Quote:
Originally Posted by Threshold
Посмотреть сообщение
udb_hash returns an integer rather than a string. Whirlpool is a much better alternative than udb_hash... I suggest you start using it.

INI_SetTag(..., "DATA");

Try changing 'DATA' to 'data', see if anything changes.
Threshold Thanks... its works by changing. DATA into data. +REP
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)