[HELP]Whirlpool&Y_ini!!!
#1

So,I still have some problem with my register system,and I hope you can help me here's my code:

pawn Код:
#define PATH "/Accounts/%s.ini"

#define DIALOG_REGISTER 1
#define DIALOG_LOGIN 2

stock Accounts(playerid)
{
    new string[128],playername[MAX_PLAYER_NAME];
    GetPlayerName(playerid,playername,sizeof(playername));
    format(string,sizeof(string),PATH,playername);
    return string;
}

stock LoadRegisteredAccount(playerid)
{
   GivePlayerMoney(playerid,1000);
   SetPlayerSkin(playerid,28);
   SetPVarInt(playerid,"loggedin",1);
}

new
   Score[MAX_PLAYERS],
   Money[MAX_PLAYERS],
   Admin[MAX_PLAYERS],
   hPass[129];

stock LoadPlayerAccount_data(playerid,name[],value[])
{
     INI_String("Password",hPass,129);
     INI_Int("Money",Money[playerid]);
     INI_Int("Score",Score[playerid]);
     INI_Int("Adminlevel",Admin[playerid]);
     return 1;
}

native WP_Hash(buffer[], len, const str[]);

public OnPlayerConnect(playerid)
{
    new pName[MAX_PLAYER_NAME];
    GetPlayerName(playerid,pName,sizeof(pName));
    new connected[64];
    format(connected,sizeof(connected),"%s(%d) has joined the server",pName,playerid);
    SendClientMessageToAll(COLOR_GREY,connected);
    SendClientMessage(playerid,COLOR_GREEN,"Welcome to San Fierro RP");
    if(!fexist(Accounts(playerid)))
    {
       ShowPlayerDialog(playerid,1,DIALOG_STYLE_INPUT,"Register","Please type in a password to register: ","Register","Cancel");
    }
    else
    {
       INI_ParseFile(Accounts(playerid), "LoadPlayerAccount_%s", .bExtra = true, .extra = playerid);
       ShowPlayerDialog(playerid,2,DIALOG_STYLE_INPUT,"Login","Welcome back.Please type in your password: ","Login","Cancel");
    }
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    if(GetPVarInt(playerid,"loggedin") == 1)
    {
     new INI:PFile = INI_Open(Accounts(playerid));
     INI_SetTag(PFile,"PlayerInfo");
     INI_WriteInt(PFile,"Score",GetPlayerScore(playerid));
     INI_WriteInt(PFile,"Money",GetPlayerMoney(playerid));
     INI_WriteInt(PFile,"Adminlevel",GetPVarInt(playerid,"Adminlevel"));
     INI_Close(PFile);
    }
    new pName[MAX_PLAYER_NAME];
    new string[64];
    GetPlayerName(playerid,pName,sizeof(pName));
    format(string,sizeof(string),"%s(%d) has left the server!",pName,playerid);
    SendClientMessageToAll(COLOR_GREY,string);
    return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid==1)
    {
      if(response==1)
      {
        if(!strlen(inputtext))
        {
          PlayerPlaySound(playerid,1055,0,0,0);
          SendClientMessage(playerid,COLOR_RED,"Invalid password,please try again");
          ShowPlayerDialog(playerid,DIALOG_STYLE_INPUT,1,"Register","Please type in a password to register: ","Register","Cancel");
        }
        else
        {
         new pName[24];
         GetPlayerName(playerid,pName,sizeof(pName));
         LoadRegisteredAccount(playerid);
         SendClientMessage(playerid,COLOR_GREEN,"Succesfully registered!!!");
         PlayerPlaySound(playerid,1057,0,0,0);
         SendClientMessage(playerid,COLOR_PURPLE,"This is San Fierro RolePlay");
         SendClientMessage(playerid,COLOR_YELLOW,"Type /new for more infos about the server");
         SendClientMessage(playerid,COLOR_YELLOW,"Type /rules for server rules");
         LoadRegisteredAccount(playerid);
         new INI:PFile = INI_Open(Accounts(playerid));
         INI_SetTag(PFile,"PlayerInfo");
         WP_Hash(hPass,129,inputtext);
         INI_WriteString(PFile,"Password",hPass);
         INI_WriteInt(PFile,"Score",GetPlayerScore(playerid));
         INI_WriteInt(PFile,"Money",GetPlayerMoney(playerid));
         INI_WriteInt(PFile,"Adminlevel",0);
         INI_Close(PFile);
        }
      }
      if(response==0)
      {
        SendClientMessage(playerid,COLOR_GREEN,"I hope you will be back soon");
        Kick(playerid);
      }
    }
    if(dialogid==2)
    {
     if(response==1)
     {
        WP_Hash(hPass,129,inputtext);
        if(strcmp(inputtext,hPass,true))
        {
         SendClientMessage(playerid,COLOR_GREEN,"Succesfully logged!!!");
         PlayerPlaySound(playerid,1057,0,0,0);
         SendClientMessage(playerid,COLOR_PURPLE,"This is San Fierro RolePlay");
         SendClientMessage(playerid,COLOR_YELLOW,"Type /new for more infos about the server");
         SendClientMessage(playerid,COLOR_YELLOW,"Type /rules for server rules");
         SetPlayerScore(playerid,Score[playerid]);
         GivePlayerMoney(playerid,Money[playerid]);
         SetPVarInt(playerid,"Adminlevel",Admin[playerid]);
         SetPVarInt(playerid,"loggedin",1);
        }
        else
        {
         PlayerPlaySound(playerid,1055,0,0,0);
         SendClientMessage(playerid,COLOR_RED,"Wrong password,please try again");
         ShowPlayerDialog(playerid,2,DIALOG_STYLE_INPUT,"Login","Welcome back.Please type in your password: ","Login","Cancel");
        }
     }
     if(response==0)
     {
        SendClientMessage(playerid,COLOR_GREEN,"I hope you will be back soon");
        Kick(playerid);
     }
    }
    return 1;
}
The only problem is that when I login,if I type-in a wrong password it still logs me in,and here's a question for ******,yes,your hasshing password system looks nice,but what if a player aasks me to change his password then what would you do?
Reply
#2

I had the same problem too, but now it's fine.
Replace
pawn Код:
#include < YSI\y_ini >
To
pawn Код:
#define MAX_INI_ENTRY_TEXT 130
#include < YSI\y_ini >
// NOTE: "#define MAX_INI_ENTRY_TEXT 130" must be before the y_ini include.
Reply
#3

nope,still logs me in,even if I type a wrong password
Reply
#4

First of all use enums for this.
Replace these
pawn Код:
new
   Score[MAX_PLAYERS],
   Money[MAX_PLAYERS],
   Admin[MAX_PLAYERS],
   hPass[129];
To
pawn Код:
enum uData
{
   Score,
   Money,
   Admin,
   hPass[ 129 ]
}
new
    UserData[ MAX_PLAYERS ][ uData ];
Also, replace
pawn Код:
stock LoadPlayerAccount_data(playerid,name[],value[])
{
     INI_String("Password",hPass,129);
     INI_Int("Money",Money[playerid]);
     INI_Int("Score",Score[playerid]);
     INI_Int("Adminlevel",Admin[playerid]);
     return 1;
}
To
pawn Код:
forward LoadPlayerAccount_data( playerid, name[ ], value[ ] );
public LoadPlayerAccount_data( playerid, name[ ], value[ ] )
{
     INI_String( "Password", UserData[ playerid ][ hPass ], 129 ) ;
     INI_Int( "Money", UserData[ playerid ][ Money ] );
     INI_Int( "Score", UserData[ playerid ][ Score ] );
     INI_Int( "Adminlevel", UserData[ playerid ][ Admin ] );
     return 1;
}
And this
pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid==1) {
        if(response==1) {
            if(!strlen(inputtext)) {
                PlayerPlaySound(playerid,1055,0,0,0);
                SendClientMessage(playerid,COLOR_RED,"Invalid password,please try again");
                ShowPlayerDialog(playerid,DIALOG_STYLE_INPUT,1,"Register","Please type in a password to register: ","Register","Cancel");
            }
            else {
                new pName[24];
                GetPlayerName(playerid,pName,sizeof(pName));
                LoadRegisteredAccount(playerid);
                SendClientMessage(playerid,COLOR_GREEN,"Succesfully registered!!!");
                PlayerPlaySound(playerid,1057,0,0,0);
                SendClientMessage(playerid,COLOR_PURPLE,"This is San Fierro RolePlay");
                SendClientMessage(playerid,COLOR_YELLOW,"Type /new for more infos about the server");
                SendClientMessage(playerid,COLOR_YELLOW,"Type /rules for server rules");
                LoadRegisteredAccount(playerid);
                new INI:PFile = INI_Open(Accounts(playerid));
                INI_SetTag(PFile,"PlayerInfo");
                WP_Hash(hPass,129,inputtext);
                INI_WriteString(PFile,"Password",hPass);
                INI_WriteInt(PFile,"Score",GetPlayerScore(playerid));
                INI_WriteInt(PFile,"Money",GetPlayerMoney(playerid));
                INI_WriteInt(PFile,"Adminlevel",0);
                INI_Close(PFile);
            }
        }
        if(response==0) {
            SendClientMessage(playerid,COLOR_GREEN,"I hope you will be back soon");
            Kick(playerid);
        }
    }
    // Rest
To
pawn Код:
public OnDialogResponse( playerid, dialogid, response, listitem, inputtext[ ] )
{
    if( dialogid == 1 ) {
        if( response == 1 ) {
            if( !strlen( inputtext ) ) {
                PlayerPlaySound (playerid, 1055, 0, 0, 0 );
                SendClientMessage( playerid, COLOR_RED, "Invalid password,please try again" );
                ShowPlayerDialog( playerid, DIALOG_STYLE_INPUT, 1, "Register", "Please type in a password to register: ", "Register", "Cancel" );
            }
            else {
                new
                    hashed_password[ 129 ], pName[ 24 ];

                WP_Hash( hashed_password, sizeof( hashed_password ), inputtext );
                GetPlayerName( playerid, pName, sizeof( pName ) );
                LoadRegisteredAccount( playerid );
                SendClientMessage( playerid, COLOR_GREEN, "Succesfully registered!!!" );
                PlayerPlaySound( playerid, 1057, 0, 0, 0 );
                SendClientMessage( playerid, COLOR_PURPLE, "This is San Fierro RolePlay" );
                SendClientMessage( playerid, COLOR_YELLOW, "Type /new for more infos about the server" );
                SendClientMessage( playerid, COLOR_YELLOW, "Type /rules for server rules" );
                LoadRegisteredAccount( playerid );
                new INI:PFile = INI_Open( Accounts( playerid ) );
                INI_SetTag( PFile, "PlayerInfo" );
                INI_WriteString( PFile, "Password", hashed_password );
                INI_WriteInt( PFile, "Score", GetPlayerScore( playerid ) );
                INI_WriteInt( PFile, "Money", GetPlayerMoney( playerid ) );
                INI_WriteInt( PFile, "Adminlevel", 0 );
                INI_Close( PFile );
            }
        }
        if( response == 0 ) {
            SendClientMessage( playerid, COLOR_GREEN, "I hope you will be back soon" );
            Kick( playerid );
        }
    }
    // Rest
Last,
pawn Код:
// On Login
new
    hashed_password[ 129 ];

WP_Hash( hashed_password, sizeof( hashed_password ), inputtext );
if( !strcmp( hashed_password, UserData[ playerid ][ hPass ] ) )
{
    INI_ParseFile( Accounts( playerid ), "LoadPlayerAccount_%s", .bExtra = true, .extra = playerid );
    // Rest of settings.
else
{
    // Kick...
}
In conclusion, if you are using the last version of whirlpool, you should have this at the top
pawn Код:
#include < a_samp >

#define MAX_INI_ENTRY_TEXT 130
#include < YSI\y_ini >
// Rest
Reply
#5

Thanks,Dwane,but how can I tell you,what I hate the most is copy-pasting,I want my code to be original not scratched from SAMP topics.Even if 1% of my entire gamemode code is copied,and 99% is original,I still feel like 99% it's copied,I don't know if you get my feeling.Therefor,I'd like if you,or someone else,can help by modifying my code AS LESS as possible.Thanks in advance for help and understanding.
Reply
#6

pawn Код:
#define MAX_INI_ENTRY_TEXT 130
#include <YSI/y_ini>

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

#define DIALOG_REGISTER 1
#define DIALOG_LOGIN 2

stock Accounts(playerid)
{
    new string[128],playername[MAX_PLAYER_NAME];
    GetPlayerName(playerid,playername,sizeof(playername));
    format(string,sizeof(string),PATH,playername);
    return string;
}

stock LoadRegisteredAccount(playerid)
{
   GivePlayerMoney(playerid,1000);
   SetPlayerSkin(playerid,28);
   SetPVarInt(playerid,"loggedin",1);
}

new
   Score[MAX_PLAYERS],
   Money[MAX_PLAYERS],
   Admin[MAX_PLAYERS],
   hPass[129][MAX_PLAYERS];

stock LoadPlayerAccount_data(playerid,name[],value[])
{
     INI_String("Password",hPass[playerid],129);
     INI_Int("Money",Money[playerid]);
     INI_Int("Score",Score[playerid]);
     INI_Int("Adminlevel",Admin[playerid]);
     return 1;
}

native WP_Hash(buffer[], len, const str[]);

public OnPlayerConnect(playerid)
{
    new pName[MAX_PLAYER_NAME];
    GetPlayerName(playerid,pName,sizeof(pName));
    new connected[64];
    format(connected,sizeof(connected),"%s(%d) has joined the server",pName,playerid);
    SendClientMessageToAll(COLOR_GREY,connected);
    SendClientMessage(playerid,COLOR_GREEN,"Welcome to San Fierro RP");
    if(!fexist(Accounts(playerid)))
    {
       ShowPlayerDialog(playerid,1,DIALOG_STYLE_INPUT,"Register","Please type in a password to register: ","Register","Cancel");
    }
    else
    {
       INI_ParseFile(Accounts(playerid), "LoadPlayerAccount_%s", .bExtra = true, .extra = playerid);
       ShowPlayerDialog(playerid,2,DIALOG_STYLE_INPUT,"Login","Welcome back.Please type in your password: ","Login","Cancel");
    }
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    if(GetPVarInt(playerid,"loggedin") == 1)
    {
     new INI:PFile = INI_Open(Accounts(playerid));
     INI_SetTag(PFile,"PlayerInfo");
     INI_WriteInt(PFile,"Score",GetPlayerScore(playerid));
     INI_WriteInt(PFile,"Money",GetPlayerMoney(playerid));
     INI_WriteInt(PFile,"Adminlevel",GetPVarInt(playerid,"Adminlevel"));
     INI_Close(PFile);
    }
    new pName[MAX_PLAYER_NAME];
    new string[64];
    GetPlayerName(playerid,pName,sizeof(pName));
    format(string,sizeof(string),"%s(%d) has left the server!",pName,playerid);
    SendClientMessageToAll(COLOR_GREY,string);
    return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid==1)
    {
      if(response==1)
      {
        if(!strlen(inputtext))
        {
          PlayerPlaySound(playerid,1055,0,0,0);
          SendClientMessage(playerid,COLOR_RED,"Invalid password,please try again");
          ShowPlayerDialog(playerid,DIALOG_STYLE_INPUT,1,"Register","Please type in a password to register: ","Register","Cancel");
        }
        else
        {
         new pName[24];
         GetPlayerName(playerid,pName,sizeof(pName));
         LoadRegisteredAccount(playerid);
         SendClientMessage(playerid,COLOR_GREEN,"Succesfully registered!!!");
         PlayerPlaySound(playerid,1057,0,0,0);
         SendClientMessage(playerid,COLOR_PURPLE,"This is San Fierro RolePlay");
         SendClientMessage(playerid,COLOR_YELLOW,"Type /new for more infos about the server");
         SendClientMessage(playerid,COLOR_YELLOW,"Type /rules for server rules");
         LoadRegisteredAccount(playerid);
         new INI:PFile = INI_Open(Accounts(playerid));
         INI_SetTag(PFile,"PlayerInfo");
         new hashPass[129];
         WP_Hash(hashPass,129,inputtext);
         INI_WriteString(PFile,"Password",hashPass);
         INI_WriteInt(PFile,"Score",GetPlayerScore(playerid));
         INI_WriteInt(PFile,"Money",GetPlayerMoney(playerid));
         INI_WriteInt(PFile,"Adminlevel",0);
         INI_Close(PFile);
        }
      }
      if(response==0)
      {
        SendClientMessage(playerid,COLOR_GREEN,"I hope you will be back soon");
        Kick(playerid);
      }
    }
    if(dialogid==2)
    {
     if(response==1)
     {
        new hashPass[129];
        WP_Hash(hashPass,129,inputtext);
        if(!strcmp(hashPass,hPass[playerid]))
        {
         SendClientMessage(playerid,COLOR_GREEN,"Succesfully logged!!!");
         PlayerPlaySound(playerid,1057,0,0,0);
         SendClientMessage(playerid,COLOR_PURPLE,"This is San Fierro RolePlay");
         SendClientMessage(playerid,COLOR_YELLOW,"Type /new for more infos about the server");
         SendClientMessage(playerid,COLOR_YELLOW,"Type /rules for server rules");
         SetPlayerScore(playerid,Score[playerid]);
         GivePlayerMoney(playerid,Money[playerid]);
         SetPVarInt(playerid,"Adminlevel",Admin[playerid]);
         SetPVarInt(playerid,"loggedin",1);
        }
        else
        {
         PlayerPlaySound(playerid,1055,0,0,0);
         SendClientMessage(playerid,COLOR_RED,"Wrong password,please try again");
         ShowPlayerDialog(playerid,2,DIALOG_STYLE_INPUT,"Login","Welcome back.Please type in your password: ","Login","Cancel");
        }
     }
     if(response==0)
     {
        SendClientMessage(playerid,COLOR_GREEN,"I hope you will be back soon");
        Kick(playerid);
     }
    }
    return 1;
}
OK,so Dwane,I didn't copy your code[I hate copy-paste] but I've modified my variables to ur ones,u know,just take a look and tell me what's wrong(Problem:Logs me in for wrong password/good password/empty text(LOL!))
Reply
#7

Your mistake is the tag. Here is PlayerInfo.
pawn Код:
INI_SetTag(PFile,"PlayerInfo");
And the tag on loading is data
pawn Код:
stock LoadPlayerAccount_data(playerid,name[],value[])
{
     INI_String("Password",hPass[playerid],129);
     INI_Int("Money",Money[playerid]);
     INI_Int("Score",Score[playerid]);
     INI_Int("Adminlevel",Admin[playerid]);
     return 1;
}
Well, you need to change the tag to data as you are using.
pawn Код:
INI_SetTag(PFile,"data");
And I am not sure about the loading from stock, but replace it with a Callback to be sure!
pawn Код:
// From:
stock LoadPlayerAccount_data(playerid,name[],value[])
// To:
forward LoadPlayerAccount_data(playerid,name[],value[]);
public LoadPlayerAccount_data(playerid,name[],value[])
Reply
#8

OMG,thanks Dwane now it's working,and also thanks to you now I understand better Y_Ini & Whirlpool.I gave u rep.No need to say ur welcome.

"TOPIC CLOSED!!!"(at last)
Reply
#9

No problem Cjgogo. Glad to hear that it works.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)