SA-MP Forums Archive
Problem Hash Pass - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Problem Hash Pass (/showthread.php?tid=412033)



Problem Hash Pass - ala67 - 31.01.2013

Hi all, I have a server with a registration system dialog, but all of this, I have no hash and do not even know how to do it.
I tried Whirpool, but I only made ​​things worse.
Код HTML:
Already functioning system login, but I would like to put a hash
I publish my recording system:
Код:
public LoginDialog(playerid)
{
        new accstring[128];
        format(accstring, sizeof(accstring), "CRP_Scriptfiles/Accounts/%s.ini", PlayerName(playerid));
        new File: hFile = fopen(accstring, io_read);
        if (hFile)
        {
            fclose(hFile);
            new name[MAX_PLAYER_NAME];
            GetPlayerName(playerid, name, sizeof(name));
            new girismsg[256];
            format(girismsg,256,"{54da00}Benvenuto {54da00}utente,{54da00}Digita la {54da00}tua password:");//54da00 //ffffff //ff0000
            ShowPlayerDialog(playerid,12346,DIALOG_STYLE_INPUT,"Login",girismsg,"Login","Esci");
        }
        else
         {
            new name[MAX_PLAYER_NAME];
            GetPlayerName(playerid, name, sizeof(name));
            new kayitmsg[256];
            format(kayitmsg,256,"{ff0000}Benvenuto utente,{ff0000}Digita la {ff0000}password desiderata:");
            ShowPlayerDialog(playerid,12345,DIALOG_STYLE_INPUT,"Registrazione",kayitmsg,"Registrati","Esci");
        }
        return 1;
}
Код:
public OnPlayerLogin(playerid,password[])
{
    new string2[128];
    format(string2, sizeof(string2), "CRP_Scriptfiles/Accounts/%s.ini", PlayerName(playerid));
    new File: UserFile = fopen(string2, io_read);
    if ( UserFile )
    {
        new PassData[256];
        new keytmp[256], valtmp[256];
        fread( UserFile , PassData , sizeof( PassData ) );
        keytmp = ini_GetKey( PassData );
        if( strcmp( keytmp , "Key" , true ) == 0 )
        {
            valtmp = ini_GetValue( PassData );
            strmid(PlayerInfo[playerid][pKey], valtmp, 0, strlen(valtmp)-1, 255);
        }
        if(strcmp(PlayerInfo[playerid][pKey],password, true ) == 0 )
        {
                new key[ 256 ] , val[ 256 ];
                new Data[ 256 ];
                while ( fread( UserFile , Data , sizeof( Data ) ) )
                {
                    key = ini_GetKey( Data );
                    if( strcmp( key , "Level" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pLevel] = strval( val ); }
                    if( strcmp( key , "AdminLevel" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pAdmin] = strval( val ); }
                    if( strcmp( key , "DonateRank" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pDonateRank] = strval( val ); }
                    if( strcmp( key , "Registered" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pRegistered] = strval( val ); }
                    if( strcmp( key , "Sex" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pSex] = strval( val ); }
                    if( strcmp( key , "City" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pCity] = strval( val ); }
                    if( strcmp( key , "Helper" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pHelper] = strval( val ); }
               }
                fclose(UserFile);
        }
        else
        {
            SendClientMessage(playerid, COLORETARGA, "{54da00}Passwo{54da00}rd Err{54da00}ata!");
            new name[MAX_PLAYER_NAME];
            tentativilogin[playerid] += 1;
            if(tentativilogin[playerid] == 3) { Kick(playerid); }
            GetPlayerName(playerid, name, sizeof(name));
            new girismsg[256];
            format(girismsg,256,"{ffffff}Hai inserito una {ffffff}password errata, {ffffff}Inserisci la password:");
            ShowPlayerDialog(playerid,12346,DIALOG_STYLE_INPUT,"login",girismsg,"Login","Esci");
            fclose(UserFile);
            return 1;
        }
        if(PlayerInfo[playerid][pFaction] != 255)
        {
            if(DynamicFactions[PlayerInfo[playerid][pFaction]][fUseColor])
            {
                SetPlayerToFactionColor(playerid);
            }
         }
         else
         {
            SetPlayerColor(playerid,COLOR_CIVILIAN);
        }
        if(PlayerInfo[playerid][pBanned])
        {
         SendClientMessage(playerid, COLOR_LIGHTRED, "Rifatti un account, perche questo и Bannato");
        KickPlayer(playerid,"GH","account bannato");
        }
        if(PlayerInfo[playerid][pRegistered] == 0)
        {
            TogglePlayerControllable(playerid,1);
            PlayerInfo[playerid][pLevel] = 1;
            PlayerInfo[playerid][pBank] = 0;
            PlayerInfo[playerid][pSkin] = 29;
            PlayerInfo[playerid][pCash] = 0;
            gPlayerLogged[playerid] = 1;
             SetSpawnInfo(playerid, 0, PlayerInfo[playerid][pSkin],CivilianSpawn[X],CivilianSpawn[Y],CivilianSpawn[Z],0,0,0,0,0,0,0);
            SpawnPlayer(playerid);
            SetTimerEx("TempoCasaCJ", 1000, false, "i", playerid);
            SpawnCasa[playerid] = 1;
            SetPlayerCash(playerid,PlayerInfo[playerid][pCash]);
            ShowPlayerDialog(playerid,19,DIALOG_STYLE_INPUT,"Etи","Quanti anni vuoi avere? Digita un etи tra 1 a 100 anni","Avanti","Annulla");
            PlayerPlaySound(playerid, 1069, 0.0, 0.0, 0.0);
           // ShowPlayerDialog(playerid,1,DIALOG_STYLE_LIST,"Di dove sei?","BAYSIDE/nLAS VENTURAS/nLOS SANTOS/nFORT CARSON/nSAN FIERRO","Ok","Annulla");
                  }
        
        if(PlayerInfo[playerid][pRegistered] == 1)
        {
        SetPlayerSkin(playerid,PlayerInfo[playerid][pSkin]);
        SetPlayerCash(playerid,PlayerInfo[playerid][pCash]);
        gPlayerLogged[playerid] = 1;
        SetSpawnInfo(playerid, 0, PlayerInfo[playerid][pSkin],CivilianSpawn[X],CivilianSpawn[Y],CivilianSpawn[Z],0,0,0,0,0,0,0);
        SpawnPlayer(playerid);
        SetPlayerColor(playerid,COLOR_CIVILIAN);
        PlayerPlaySound(playerid, 1069, 0.0, 0.0, 0.0);
        }
    }
    return 1;
}
Код:
else if(dialogid == 12345)
        {
                if (response == 1)
                {
                    if(strlen(inputtext))
                    {
                        OnPlayerRegister(playerid,inputtext);
                        OnPlayerLogin(playerid,inputtext);
                    }
                    else if(!strlen(inputtext))
                    {
                        new name[MAX_PLAYER_NAME];
                        GetPlayerName(playerid, name, sizeof(name));
                        new kayitmsg[256];
                        format(kayitmsg,256,"Benvenuto utente\nDigita la password desiderata:");
                        ShowPlayerDialog(playerid,12345,DIALOG_STYLE_INPUT,"Registrazione",kayitmsg,"Registrati","Esci");
                    }
                }
                else
                {
                     Kick(playerid);
                 }
         }
         else if(dialogid == 12346)
         {
                if (response == 1)
                {
                    if(strlen(inputtext))
                    {
                        OnPlayerLogin(playerid,inputtext);
                    }
                    else if(!strlen(inputtext))
                    {
                        new name[MAX_PLAYER_NAME];
                        GetPlayerName(playerid, name, sizeof(name));
                        new girismsg[256];
                        format(girismsg,256,"Benvenuto utente\nDigita la tua password:");
                        ShowPlayerDialog(playerid,12346,DIALOG_STYLE_INPUT,"Login",girismsg,"Login","Esci");
                    }
                }
                  else
                {
                     Kick(playerid);
                 }
        }
I'm Italian


Re: Problem Hash Pass - Zamaroht - 31.01.2013

First you need a hashing function, which recieves a string as parameters, and returns a new encrypted string. The new encrypted string is what you would store in your database.
When the players try to log in, you ask them to input a password. You apply the hash function to the password they wrote, and compare if the hash is the same to the one you have stored. If it is, then the login was succesful, if it wasn't, then not.


Re: Problem Hash Pass - ala67 - 01.02.2013

Quote:
Originally Posted by Zamaroht
Посмотреть сообщение
First you need a hashing function, which recieves a string as parameters, and returns a new encrypted string. The new encrypted string is what you would store in your database.
When the players try to log in, you ask them to input a password. You apply the hash function to the password they wrote, and compare if the hash is the same to the one you have stored. If it is, then the login was succesful, if it wasn't, then not.
I like this feature, I can insert a link to a guide on the forum?
I do not know what to do!
thanks in advance


Re: Problem Hash Pass - ala67 - 03.02.2013

Reply??