[Tutorial] Using new SHA-256 function
#28

pawn Code:
forward LoadUser_data(playerid, name[], value[]);
public LoadUser_data(playerid, name[], value[])
{
    INI_String("Name", pInfo[playerid][pName]);
    INI_String("Password", pInfo[playerid][pPass]);
    INI_String("Salt", pInfo[playerid][pSalt]);
    INI_Int("Money", pInfo[playerid][pMoney]);
    INI_Int("Score", pInfo[playerid][pScore]);
    INI_Int("Kills", pInfo[playerid][pKills]);
    INI_Int("Deaths", pInfo[playerid][pDeaths]);
    INI_Int("Admin", pInfo[playerid][pAdmin]);
    return 1;
}

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

public OnPlayerConnect(playerid)
{
    if(fexist(UserPath(playerid)))
    {
        INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "MC:RP - Accesso Utente", "Bentornato!\nQuesto account e' gia' registrato.\nDigita la tua password per accedere.", "Accedi", "Esci");
    }
    else
    {
        ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "MC:RP - Registrazione Utente", "Benvenuto!\nQuesto account non e' registrato.\nDigita una password per registrarti.", "Registra", "Esci");
    }
    return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch(dialogid)
    {
        case DIALOG_REGISTER:
        {
            if(!response) return Kick(playerid);
            if(response)
            {
                if(!strlen(inputtext))
                {
                    SendClientMessage(playerid, COLOR_RED, "[ERRORE]: Devi digitare una password per poterti registrare!");
                    ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "MC:RP - Registrazione Utente", "Benvenuto!\nQuesto account non e' registrato.\nDigita una password per registrarti.", "Registra", "Esci");
                }
                new salt[11];
                for(new i; i < 10; i++)
                {
                    salt[i] = random(79) + 47;
                }
                salt[10] = 0;
                SHA256_PassHash(inputtext, salt, pInfo[playerid][pPass], 65);

                new INI:File = INI_Open(UserPath(playerid));
                INI_SetTag(File, "Player's Data");
                INI_WriteString(File, "Name", Name);
                INI_WriteString(File, "Password", pInfo[playerid][pPass]);
                INI_WriteString(File, "Salt", salt);
                INI_WriteInt(File, "Money", 0);
                INI_WriteInt(File, "Score", 0);
                INI_WriteInt(File, "Kills", 0);
                INI_WriteInt(File, "Deaths", 0);
                INI_WriteInt(File, "Admin", 0);
                INI_Close(File);
            }
            return 1;
        }

        case DIALOG_LOGIN:
        {
            if(!response) return Kick(playerid);
            if(response)
            {
                new hash[65];
                SHA256_PassHash(inputtext, pInfo[playerid][pSalt], hash, 64);
                if(!strcmp(hash, pInfo[playerid][pPass]))
                {
                    INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
                    GivePlayerMoney(playerid, pInfo[playerid][pMoney]);
                }
                else
                {
                    SendClientMessage(playerid, COLOR_RED, "[ERRORE]: Hai digitato una password errata. Riprova!");
                    ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "MC:RP - Accesso Utente", "Bentornato!\nQuesto account e' gia' registrato.\nDigita la tua password per accedere.", "Accedi", "Esci");
                }
                return 1;
            }
        }
    }
    return 1;
}
Why I can't login? What's wrong? It saves everything but I can't access.
Sorry for opening older topics...
Reply


Messages In This Thread
Using new SHA-256 function - by dominik523 - 12.07.2015, 10:12
Re: Using new SHA-256 function - by lukewid - 12.07.2015, 11:32
Re: Using new SHA-256 function - by lexjusto - 13.07.2015, 02:27
Re: Using new SHA-256 function - by dominik523 - 13.07.2015, 05:53
Re: Using new SHA-256 function - by zT KiNgKoNg - 13.07.2015, 08:14
Re: Using new SHA-256 function - by dominik523 - 13.07.2015, 08:37
Re: Using new SHA-256 function - by Lordzy - 13.07.2015, 13:44
Re: Using new SHA-256 function - by dominik523 - 13.07.2015, 17:25
Re: Using new SHA-256 function - by Youssef221 - 13.07.2015, 23:53
Re: Using new SHA-256 function - by zT KiNgKoNg - 14.07.2015, 00:06
Re: Using new SHA-256 function - by yugecin - 14.07.2015, 00:06
Re: Using new SHA-256 function - by scaunel - 14.07.2015, 01:10
Re: Using new SHA-256 function - by dominik523 - 14.07.2015, 08:36
Re: Using new SHA-256 function - by Hiddos - 14.07.2015, 10:59
Re: Using new SHA-256 function - by dominik523 - 14.07.2015, 11:58
Re: Using new SHA-256 function - by Youssef221 - 14.07.2015, 13:28
Re: Using new SHA-256 function - by Youssef221 - 14.07.2015, 16:41
Re: Using new SHA-256 function - by dominik523 - 14.07.2015, 17:08
Re: Using new SHA-256 function - by Cyber123 - 14.07.2015, 23:05
Re: Using new SHA-256 function - by RaeF - 16.07.2015, 03:12
Re: Using new SHA-256 function - by rymax99 - 16.07.2015, 03:48
Re: Using new SHA-256 function - by dominik523 - 16.07.2015, 07:46
Re: Using new SHA-256 function - by AchievementMaster360 - 20.07.2015, 20:04
Re: Using new SHA-256 function - by venomlivno8 - 15.01.2016, 09:45
Re: Using new SHA-256 function - by Vince - 15.01.2016, 17:50
Re: Using new SHA-256 function - by PrO.GameR - 18.08.2016, 20:49
Re: Using new SHA-256 function - by SKAzini - 18.08.2016, 21:36
Re: Using new SHA-256 function - by BugsBunny - 19.02.2017, 11:12
Respuesta: Using new SHA-256 function - by Juance - 28.02.2017, 12:39
Re: Using new SHA-256 function - by Phreak - 21.04.2018, 12:19
Re: Using new SHA-256 function - by ranme15 - 21.04.2018, 13:33
Re: Using new SHA-256 function - by JesterlJoker - 21.04.2018, 16:47
Re: Using new SHA-256 function - by AmigaBlizzard - 22.04.2018, 20:46
Re: Using new SHA-256 function - by JesterlJoker - 23.04.2018, 11:00
Re: Using new SHA-256 function - by iKarim - 23.04.2018, 16:11
Re: Using new SHA-256 function - by AmirSavand - 11.09.2018, 23:08

Forum Jump:


Users browsing this thread: 1 Guest(s)