Jump to content
  • 0

Problema SHA256.


SUPREME.

Question

 

 

Salut, am facut sistemul de logare, respectiv de inregistrare sa se cripteze in sha256, faza e ca este o problema cand incerc sa imi fac cont.

 

 

In mysql_error imi apare asta

 

1RH49k3.png

 

La on player register am asta

 

 

public OnPlayerRegister(playerid, password[])


{
    if(IsPlayerConnected(playerid))
    {
        new playername3[MAX_PLAYER_NAME];
        GetPlayerName(playerid, playername3, sizeof(playername3));
        new Str[500],y,m,d,h,mi,s;
        getdate(y, m, d);
        gettime(h, mi, s);
        for (new i = 0; i < 16; i++) PlayerInfo[playerid][pSalt] = random(94) + 33;
        SHA256_PassHash(password, PlayerInfo[playerid][pSalt], PlayerInfo[playerid][pKey], 65);
        mysql_format(SQL,Str,sizeof(Str),"INSERT INTO `users` (`name`,`password`,`RegisterDate`,`salt`) VALUES ('%s','%s','%d-%d-%d %d:%d:%d','%s')",playername3,PlayerInfo[playerid][pKey],y,m,d,h,mi,s,PlayerInfo[playerid][pSalt]);
        mysql_tquery(SQL,Str,"","");
        strmid(PlayerInfo[playerid][pKey], password, 0, strlen(password), 255);
        PlayerInfo[playerid][pCash] = GetPlayerCash(playerid);

 

 

La on player login am asta

 

 

 

public OnPlayerLogin(playerid,password[])


{
    new playername2[MAX_PLAYER_NAME],playerip[16];
    GetPlayerName(playerid, playername2, sizeof(playername2));
    GetPlayerIp(playerid,playerip,sizeof(playerip));
    if(NumIp(playerip, playerid) >= 3 && !IsBotOnIP(playerip))
    {
         SendClientMessage(playerid, COLOR_LIGHTRED, "There are already 2 players connected with same IP.");
         KickEx(playerid);
         return 1;
    }
    new qstr[256];
    new hashed_pass[65];
    SHA256_PassHash(password, PlayerInfo[playerid][pSalt], hashed_pass, 65);
    format(qstr,sizeof(qstr),"SELECT * FROM users WHERE `name`='%s' AND `password`='%s'",playername2,hashed_pass);
    new Cache: pass = mysql_query(SQL,qstr);
    if(cache_get_row_count() > 0)
    {
        cache_get_field_content(0, "password", PlayerInfo[playerid][pKey], SQL, 130);
        cache_get_field_content(0, "name", PlayerInfo[playerid][pNormalName], SQL, 130);
        cache_get_field_content(0, "Salt", PlayerInfo[playerid][pSalt], SQL, 17);

 

 

La on player connect am asta 

 

 

    new Cache:csalt,squery[128];


    mysql_format(SQL, squery, sizeof(squery), "SELECT `Salt` FROM `users` WHERE `name` = '%s'", GetName(playerid));
    csalt = mysql_query(SQL, squery,true);
    if(cache_num_rows() > 0)
    {
        cache_get_field_content(0, "Salt", PlayerInfo[playerid][pSalt], SQL,17);
    }
    cache_delete(csalt, SQL);

 

 

Si la "    if(dialogid == DIALOG_LOGIN2 || dialogid == DIALOG_LOGIN3)" am asta

 

 

    if(dialogid == DIALOG_LOGIN2 || dialogid == DIALOG_LOGIN3)


    {
        if(response)
        {
            if(strlen(inputtext))
            {
                new hash[129];
                   SHA256_PassHash(inputtext, PlayerInfo[playerid][pSalt], hash, 64);
                   if(!strcmp(hash, PlayerInfo[playerid][pKey]))
                OnPlayerLogin(playerid,hash);
            }
            else
            {
                new stringyy[320];
                gPlayerLogTries[playerid] -= 1;
                if(gPlayerLogTries[playerid] == 1 || gPlayerLogTries[playerid] == 0)
                {
                    format(stringyy,sizeof(stringyy),"Incorrect password. You have %d remaining login attempts left.", gPlayerLogTries[playerid]);
                    SendClientMessage(playerid, COLOR_RED2, stringyy);
                }
                ShowPlayerDialog(playerid,DIALOG_LOGIN2,DIALOG_STYLE_PASSWORD,"SERVER: Login","Welcome to the GTA-SAMP RPG Server.\n\nPlease enter your password below!","Login","Cancel");
                if(gPlayerLogTries[playerid] == -1)
                {
                    new stringkick[256],loginname[30];
                    GetPlayerName(playerid, loginname, sizeof(loginname));
                    format(stringkick, sizeof(stringkick), "AdmWarn: {FFFFFF}%s has been kicked for entering the wrong password 2 times.",loginname);
                    ABroadCast(COLOR_RED2,stringkick,1);
                    SendClientMessage(playerid, COLOR_RED2, "You have used all available login attempts.");
                    KickEx(playerid);
                }
            }
        }
        else return KickEx(playerid);
    }[/spoier]

Edited by SUPREME.
Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Am rezolvat o parte din erori, acum ma lasa sa imi fac cont si se salveaza in baza de date, dar faza e ca imi spune parola incorecta.

 

    if(dialogid == DIALOG_LOGIN2 || dialogid == DIALOG_LOGIN3)
    {
        if(response)
        {
            if(strlen(inputtext))
            {
                new tmppass[129];
                SHA256_PassHash(inputtext, PlayerInfo[playerid][pSalt], tmppass, 64);
                if(!strcmp(tmppass, PlayerInfo[playerid][pKey]))
                //WP_Hash(tmppass, sizeof(tmppass), inputtext);
                OnPlayerLogin(playerid,tmppass);
            }
            else
            {
                new stringyy[320];
                gPlayerLogTries[playerid] -= 1;
                if(gPlayerLogTries[playerid] == 1 || gPlayerLogTries[playerid] == 0)
                {
                    format(stringyy,sizeof(stringyy),"Incorrect password. You have %d remaining login attempts left.", gPlayerLogTries[playerid]);
                    SendClientMessage(playerid, COLOR_RED2, stringyy);
                }
                ShowPlayerDialog(playerid,DIALOG_LOGIN2,DIALOG_STYLE_PASSWORD,"SERVER: Login","Welcome to the GTA-SAMP RPG Server.\n\nPlease enter your password below!","Login","Cancel");
                if(gPlayerLogTries[playerid] == -1)
                {
                    new stringkick[256],loginname[30];
                    GetPlayerName(playerid, loginname, sizeof(loginname));
                    format(stringkick, sizeof(stringkick), "AdmWarn: {FFFFFF}%s has been kicked for entering the wrong password 2 times.",loginname);
                    ABroadCast(COLOR_RED2,stringkick,1);
                    SendClientMessage(playerid, COLOR_RED2, "You have used all available login attempts.");
                    KickEx(playerid);
                }
            }
        }
        else return KickEx(playerid);
    }

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. For more details you can also review our Terms of Use and Privacy Policy.