Y_Ini - Let's do it!
#1

Hi.. i'm starting for the first time with Y_ini.. i was readed fully topic ****** and i've a problem : )

Code:
   	new INI:Account, buf[129];
	Account = INI_Open(PlayerName(playerid));
	INI_WriteInt(Account, "Password", WP_Hash(password, sizeof(buf), buf));
        INI_Close(Account);
How i can hash player password (this giving me "Password = 0' in user file)

2.. how i can get password from player file. It's too complicated for me. (Better for me is dini_Get xD - but in need to learn something stronger.)

So.. i'm waiting for the help : )
Reply
#2

To get the pass from file:
pawn Code:
new PasswordVar[ MAX_PLAYERS ];
forward GetPassword( playerid, name[ ], value[ ] );
public GetPassword( playerid, name[ ], value[ ] )
{
    if( !strcmp( name, "Password" ) )
        PasswordVar[ playerid ] = value;
    return 1;
}
pawn Code:
// To load the password
new file[ 128 ], name[ 24 ]; GetPlayerName( playerid, name, 24 );
format( file, sizeof file, "%s.ini", name );
INI_ParseFile( file, "GetPassword", false, true, playerid, true, false );
new string[ 128 ]; format( string, sizeof string, "Your password is %s", PasswordVar[ playerid ] );
SendClientMessage( playerid, 0xAAAAAA, string );
Should work.
Reply
#3

GetPassword:
Code:
error 006: must be assigned to an array
-cut-
Reply
#4

Okey.. i changed it:
Code:
GetPassword(playerid, nickname[], value)
value[] on value.

edit://
I think @UP is must be value[]. But don't know how to fix.

pawn Code:
stock OnPlayerLogin(playerid, password[])
{
    if(GetPassword(playerid, PlayerName(playerid), password))
    {
Code:
C:\Documents and Settings\Kakarotto\Pulpit\Sa-Mp Serwer 0.3c Y_INI\gamemodes\pes.pwn(2137) : error 035: argument type mismatch (argument 3)
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


1 Error.
Why? : )
Reply
#5

Try:
pawn Code:
if ( !strcmp( name, "Password" ) )
        SetPVarString( playerid, "pPass", value );
pawn Code:
new file[ 128 ], name[ 24 ]; GetPlayerName( playerid, name, 24 );
format( file, sizeof file, "%s.ini", name );
new pass[ 256 ];
GetPVarString( playerid, "pPass", pass, sizeof pass );
INI_ParseFile( file, "GetPassword", false, true, playerid, true, false );
new string[ 128 ]; format( string, sizeof string, "Your password is %s", pass );
SendClientMessage( playerid, 0xAAAAAA, string );
And delete the
pawn Code:
new PasswordVar[ MAX_PLAYERS ];
Hope it works.
Reply
#6

For your first question. The password is a string and not an int
pawn Code:
new INI:Account, buf[129];
Account = INI_Open(PlayerName(playerid));
WP_Hash(password, sizeof(buf), buf);
INI_WriteString(Account, "Password", buf);
INI_Close(Account);
Reply
#7

Quote:
Originally Posted by Fj0rtizFredde
View Post
For your first question. The password is a string and not an int
pawn Code:
new INI:Account, buf[129];
Account = INI_Open(PlayerName(playerid));
WP_Hash(password, sizeof(buf), buf);
INI_WriteString(Account, "Password", buf);
INI_Close(Account);
/imageshack/img814/8625/beztytuudvf.png


Saved to file:
Password = (nothing here)

But maybe it's my problem.

pawn Code:
stock INI_Exist(nickname[])
{
    new string[64];
    format(string, sizeof(string),"%s\%s.ini", UserFile, nickname);
    return fexist(string);
}
pawn Code:
#define UserFile                        "/Polski eXtra Serwer/Users/"
How to create player file in a folder?
Reply
#8

Account created in a folder:

pawn Code:
stock PlayerFile(playerid)
{
    new string[64];
    format(string, sizeof(string), "%s\%s.ini", UserFile, PlayerName(playerid));
    return string;
}
Now need help with that password.

pawn Code:
stock OnPlayerRegister(playerid, password[])
{
    new INI:Account, buf[129];
    Account = INI_Open(PlayerFile(playerid));
    WP_Hash(password, sizeof(buf), buf);
    INI_WriteString(Account, "Password", buf);
    INI_Close(Account);
return true;
}
pawn Code:
stock OnPlayerLogin(playerid, password[])
{
if(GetPassword(playerid, PlayerFile(playerid), password))
{
SendClientMessage
}else{
SendErrorMessage
}
return true;
}
Is all okey now?
Reply
#9

Quote:
Originally Posted by Mean
View Post
To get the pass from file:
pawn Code:
new PasswordVar[ MAX_PLAYERS ];
forward GetPassword( playerid, name[ ], value[ ] );
public GetPassword( playerid, name[ ], value[ ] )
{
    if( !strcmp( name, "Password" ) )
        PasswordVar[ playerid ] = value;
    return 1;
}
pawn Code:
// To load the password
new file[ 128 ], name[ 24 ]; GetPlayerName( playerid, name, 24 );
format( file, sizeof file, "%s.ini", name );
INI_ParseFile( file, "GetPassword", false, true, playerid, true, false );
new string[ 128 ]; format( string, sizeof string, "Your password is %s", PasswordVar[ playerid ] );
SendClientMessage( playerid, 0xAAAAAA, string );
Should work.
You are wrong! It must be a string, password aren't made just out of a large number( Depends if you want or not ).
Reply
#10

If he was wrong you can help me?
Reply
#11

Quote:
Originally Posted by Riddick94
View Post
edit://
I don't understand it:
pawn Code:
INI_ParseFile( "PlayerFile.ini", "ParsePass", .bExtra = true,  .extra = playerid );
new Str[ 129 ],
    PlayerPass[ 129 ];
GetPVarString( playerid, "pPass", PlayerPass, 129 );
foprmat( Str, 129, "%s", PlayerPass );
SendClientMessage( playerid, -1, Str );
I need to use this in OnPlayerLogin? if yes.. how?
Where is this in your new code? This is loading code, not what you just posted - that only opens the file and closes it again instantly.
Reply
#12

Can you tell me where i need to put it? in OnDialogResponse when player have a dialog login?

pawn Code:
case DIALOG_LOGOWANIE:
        {
            if(!response)Kick(playerid);
            if(response)
            {
                INI_ParseFile(PlayerFile(playerid), "GetPlayerPassword");
                new PlayerPass[129];
                GetPVarString(playerid, "pPass", PlayerPass, 129);
            if(!inputtext[0])
                {
                    SendClientMessage(playerid, COLOR_RED, "* You need to insert your password here.");
                    }else{
                    OnPlayerLogin(playerid, inputtext);
                }
Reply
#13

Anyone? i need it.
Reply
#14

I would place it in OnPlayerLogin where you are checking that the password is correct (actually slightly before there).
Reply
#15

So like that, yes?
pawn Code:
stock OnPlayerLogin(playerid, password[])
{
    INI_ParseFile(PlayerFile(playerid), "GetPlayerPassword");
    new PlayerPass[129];
    GetPVarString(playerid, "pPass", PlayerPass, 129);
    if(GetPlayerPassword(playerid, PlayerFile(playerid), password))
    {
        new INI:Account;
        Account = INI_Open(PlayerFile(playerid));

        INI_Close(Account);

        PlayerInfo[playerid][pLogged] = true;
        TogglePlayerClock(playerid, true);

        SendDeathMessage(INVALID_PLAYER_ID, playerid, ICON_CONNECT);
        SendFormattedMessageToAll(COLOR_WHITE, "***  %s [{FF003F}ID{FFFFFF}: {FF003F}%d{FFFFFF}] dołączył do serwera.", PlayerName(playerid), playerid);
        SendFormattedMessage(playerid, COLOR_LIMON, "{1BE03F}* Zalogowany jako {EDBC6D}%s {FFFFFF}[{FF003F}ID{FFFFFF}: {FF003F}%d{FFFFFF}]{1BE03F}. Witamy spowrotem na Polskim eXtra Serwerze!", PlayerName(playerid), playerid);
        }else{
        new string[128];
        format(string,sizeof(string),"{9EB8E8}Witamy ponownie {F2EE0C}%s{9EB8E8}. Proszę wpisać poniżej swoje hasło, aby zalogować się i grać:", PlayerName(playerid));
        ShowPlayerDialog(playerid, DIALOG_LOGOWANIE, DIALOG_STYLE_INPUT, "Logowanie", string, "Zaloguj", "Wyjdź");
        GameTextForPlayer(playerid, " ~n~ ~n~ ~n~ ~n~ ~n~ ~r~Nieprawidlowe haslo!", SECONDS(3), 3);
    }
    return true;
}
pawn Code:
function GetPlayerPassword(playerid, name[], value[])
{
    if(!strcmp(name, "Password"))SetPVarString(playerid, "pPass", value);
    return true;
}
pawn Code:
stock PlayerFile(playerid)
{
    new string[128];
    format(string, sizeof(string),"%s\%s.ini", UserFile, PlayerName(playerid));
    return string;
}
Reply
#16

Quote:
Originally Posted by Riddick94
View Post
So like that, yes?
pawn Code:
stock OnPlayerLogin(playerid, password[])
{
    INI_ParseFile(PlayerFile(playerid), "GetPlayerPassword");
    new PlayerPass[129];
    GetPVarString(playerid, "pPass", PlayerPass, 129);
    if(GetPlayerPassword(playerid, PlayerFile(playerid), password))
    {
        new INI:Account;
        Account = INI_Open(PlayerFile(playerid));

        INI_Close(Account);

        PlayerInfo[playerid][pLogged] = true;
        TogglePlayerClock(playerid, true);

        SendDeathMessage(INVALID_PLAYER_ID, playerid, ICON_CONNECT);
        SendFormattedMessageToAll(COLOR_WHITE, "***  %s [{FF003F}ID{FFFFFF}: {FF003F}%d{FFFFFF}] dołączył do serwera.", PlayerName(playerid), playerid);
        SendFormattedMessage(playerid, COLOR_LIMON, "{1BE03F}* Zalogowany jako {EDBC6D}%s {FFFFFF}[{FF003F}ID{FFFFFF}: {FF003F}%d{FFFFFF}]{1BE03F}. Witamy spowrotem na Polskim eXtra Serwerze!", PlayerName(playerid), playerid);
        }else{
        new string[128];
        format(string,sizeof(string),"{9EB8E8}Witamy ponownie {F2EE0C}%s{9EB8E8}. Proszę wpisać poniżej swoje hasło, aby zalogować się i grać:", PlayerName(playerid));
        ShowPlayerDialog(playerid, DIALOG_LOGOWANIE, DIALOG_STYLE_INPUT, "Logowanie", string, "Zaloguj", "Wyjdź");
        GameTextForPlayer(playerid, " ~n~ ~n~ ~n~ ~n~ ~n~ ~r~Nieprawidlowe haslo!", SECONDS(3), 3);
    }
    return true;
}
pawn Code:
function GetPlayerPassword(playerid, name[], value[])
{
    if(!strcmp(name, "Password"))SetPVarString(playerid, "pPass", value);
    return true;
}
pawn Code:
stock PlayerFile(playerid)
{
    new string[128];
    format(string, sizeof(string),"%s\%s.ini", UserFile, PlayerName(playerid));
    return string;
}
Actually, you are mixing up everything!

the function GetPlayerPassword is NOT meant to be used! Only in INI_ParseFile.

And use GetPVarString( playerid, "pPass... ) and use the string variable to check if the password is wrong.
Reply
#17

Change:

pawn Code:
if(GetPlayerPassword(playerid, PlayerFile(playerid), password))
To:

pawn Code:
if (!strcmp(PlayerPass, password))
Although, where are you hashing the password?
Reply
#18

You mean where i'm hashing password?
pawn Code:
stock OnPlayerRegister(playerid, password[])
{
    new INI:Account, buf[129];
    Account = INI_Open(PlayerFile(playerid));
    WP_Hash(buf, sizeof(buf), password);
   
    INI_WriteString(Account, "Password", buf);
    INI_WriteInt(Account, "Kasa", 10000);
    INI_WriteInt(Account, "FightStyle", FIGHT_STYLE_GRABKICK);
    INI_Close(Account);
   
    PlayerInfo[playerid][pLogged] = true;
    TogglePlayerClock(playerid, true);
   
    SendDeathMessage(INVALID_PLAYER_ID, playerid, ICON_CONNECT);
    SendFormattedMessageToAll(COLOR_WHITE, "***  %s [{FF003F}ID{FFFFFF}: {FF003F}%d{FFFFFF}] dołączył do serwera.", PlayerName(playerid), playerid);
    SendClientMessage(playerid, COLOR_LIMON, "* Twoje konto zostało utworzone. Zostałeś automatycznie zalogowany. Witamy na Polskim eXtra Serwerze!");
    SendFormattedMessage(playerid, COLOR_LIGHTRED, "* Zapamiętaj swoje hasło: {EDBC6D}-> '%s' <-", password);
    return true;
}
edit://
Not working.. need to read hashed password, yes? but how to read hashed? i know only how to write.. : d
Reply
#19

When you read the value you get the hashed password. You then need to also hash the text the user types when they log in and compare the two hashed versions.
Reply
#20

Okey, how to do that? sorry i don't know really how to make that. Can you show the code and describe it? please..
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)