MySQL - MD5+SALT
#1

Hello guys I have a problem with MD5+SALT in my map. I have a no coding passwords but I bought IP Board and I must now code the passwords. Here is some code:

Код:
public OnPlayerLogin(playerid,password[])
{

    MySQLCheckConnection();
    new string2[128];
	new playername2[MAX_PLAYER_NAME];
    GetPlayerName(playerid, playername2, sizeof(playername2));


	MySQLFetchAcctSingle(PlayerInfo[playerid][pSQLID], "Password", PlayerInfo[playerid][pKey]);
	if(strcmp(PlayerInfo[playerid][pKey],password, true ) == 0 && strlen(password) > 0)
	{
	//printf( "gracz interior poczatek logowania = %d ", PlayerInfo[playerid][pInt]);
		new Data[1024];
		new Field[149][64];
		SendClientMessage(playerid,COLOR_COM,"A-RP: Proszę czekać, trwa wczytywanie danych...");
		MySQLFetchAcctRecord(PlayerInfo[playerid][pSQLID], Data);
		/*printf("Data: %s",Data);*/
		split(Data, Field, '|');
		PlayerInfo[playerid][pStatus] = strval(Field[3]);
    	PlayerInfo[playerid][pAdmin] = strval(Field[4]);
    	PlayerInfo[playerid][pGID] = strval(Field[5]);
        PlayerInfo[playerid][pConnectTime] = strval(Field[6]);
        PlayerInfo[playerid][pReg] = strval(Field[7]);
        PlayerInfo[playerid][pSex] = strval(Field[8]);
        PlayerInfo[playerid][pAge] = strval(Field[9]);
        PlayerInfo[playerid][pOrigin] = Field[10];
        PlayerInfo[playerid][pOnline] = strval(Field[11]);
        PlayerInfo[playerid][pMuted] = strval(Field[12]);
        PlayerInfo[playerid][pCash] = strval(Field[13]);
        PlayerInfo[playerid][pAccount] = strval(Field[14]);
        PlayerInfo[playerid][pCrimes] = strval(Field[15]);
        PlayerInfo[playerid][pArrested] = strval(Field[16]);
        PlayerInfo[playerid][pPhoneBook] = strval(Field[17]);
        PlayerInfo[playerid][pLottoNr] = strval(Field[18]);
        PlayerInfo[playerid][pFishes] = strval(Field[19]);
        PlayerInfo[playerid][pBiggestFish] = strval(Field[20]);
        PlayerInfo[playerid][pJob] = strval(Field[21]);
        PlayerInfo[playerid][pPktKarne] = strval(Field[22]);
        PlayerInfo[playerid][pPayCheck] = strval(Field[23]);
        PlayerInfo[playerid][pHeadValue] = strval(Field[24]);
        PlayerInfo[playerid][pJailed] = strval(Field[25]);
        PlayerInfo[playerid][pJailTime] = strval(Field[26]);
        PlayerInfo[playerid][pMats] = strval(Field[27]);
        PlayerInfo[playerid][pDrugs] = strval(Field[28]);
        PlayerInfo[playerid][pLeader] = strval(Field[29]);
        PlayerInfo[playerid][pMember] = strval(Field[30]);
        PlayerInfo[playerid][pLastUpdate] = strval(Field[31]);
        PlayerInfo[playerid][pRank] = strval(Field[32]);
        PlayerInfo[playerid][pChar] = strval(Field[33]);
        PlayerInfo[playerid][pContractTime] = strval(Field[34]);
        PlayerInfo[playerid][pDetSkill] = strval(Field[35]);
        PlayerInfo[playerid][pSexSkill] = strval(Field[36]);
        PlayerInfo[playerid][pBoxSkill] = strval(Field[37]);
        PlayerInfo[playerid][pLawSkill] = strval(Field[38]);
        PlayerInfo[playerid][pMechSkill] = strval(Field[39]);
        PlayerInfo[playerid][pJackSkill] = strval(Field[40]);
        PlayerInfo[playerid][pCarSkill] = strval(Field[41]);
        PlayerInfo[playerid][pNewsSkill] = strval(Field[42]);
        PlayerInfo[playerid][pDrugsSkill] = strval(Field[43]);
        PlayerInfo[playerid][pCookSkill] = strval(Field[44]);
        PlayerInfo[playerid][pFishSkill] = strval(Field[45]);
       	PlayerInfo[playerid][pKieszSkill] = strval(Field[46]);
     	  PlayerInfo[playerid][pDealSkill] = strval(Field[47]);
        PlayerInfo[playerid][pSHealth] = floatstr(Field[48]);
        PlayerInfo[playerid][pInt] = strval(Field[49]);
        PlayerInfo[playerid][pLocal] = strval(Field[50]);
        PlayerInfo[playerid][pTeam] = strval(Field[51]);
        PlayerInfo[playerid][pModel] = strval(Field[52]);
        PlayerInfo[playerid][pPnumber] = strval(Field[53]);
        PlayerInfo[playerid][pBMember] = strval(Field[54]);
        PlayerInfo[playerid][pBLeader] = strval(Field[55]);
        PlayerInfo[playerid][pPos_x] = floatstr(Field[56]);
        PlayerInfo[playerid][pPos_y] = floatstr(Field[57]);
        PlayerInfo[playerid][pPos_z] = floatstr(Field[58]);
        PlayerInfo[playerid][pCarLic] = strval(Field[59]);
        PlayerInfo[playerid][pFlyLic] = strval(Field[60]);
        PlayerInfo[playerid][pBikeLic] = strval(Field[61]);
        PlayerInfo[playerid][pRowerLic] = strval(Field[62]);
        PlayerInfo[playerid][pTirLic] = strval(Field[63]);
        PlayerInfo[playerid][pBusLic] = strval(Field[64]);
		      PlayerInfo[playerid][pBoatLic] = strval(Field[65]);
        PlayerInfo[playerid][pFishLic] = strval(Field[66]);
        PlayerInfo[playerid][pGunLic] = strval(Field[67]);
        PlayerInfo[playerid][pGun][0] = strval(Field[68]);
        PlayerInfo[playerid][pGun][1] = strval(Field[69]);
        PlayerInfo[playerid][pGun][2] = strval(Field[70]);
        PlayerInfo[playerid][pGun][3] = strval(Field[71]);
        PlayerInfo[playerid][pGun][4] = strval(Field[72]);
        PlayerInfo[playerid][pGun][5] = strval(Field[73]);
        PlayerInfo[playerid][pGun][6] = strval(Field[74]);
        PlayerInfo[playerid][pGun][7] = strval(Field[75]);
        PlayerInfo[playerid][pGun][8] = strval(Field[76]);
        PlayerInfo[playerid][pGun][9] = strval(Field[77]);
        PlayerInfo[playerid][pGun][10] = strval(Field[78]);
        PlayerInfo[playerid][pGun][11] = strval(Field[79]);
        PlayerInfo[playerid][pGun][12] = strval(Field[80]);
        PlayerInfo[playerid][pAmmo][0] = strval(Field[81]);
        PlayerInfo[playerid][pAmmo][1] = strval(Field[82]);
        PlayerInfo[playerid][pAmmo][2] = strval(Field[83]);
        PlayerInfo[playerid][pAmmo][3] = strval(Field[84]);
        PlayerInfo[playerid][pAmmo][4] = strval(Field[85]);
        PlayerInfo[playerid][pAmmo][5] = strval(Field[86]);
        PlayerInfo[playerid][pAmmo][6] = strval(Field[87]);
        PlayerInfo[playerid][pAmmo][7] = strval(Field[88]);
        PlayerInfo[playerid][pAmmo][8] = strval(Field[89]);
        PlayerInfo[playerid][pAmmo][9] = strval(Field[90]);
        PlayerInfo[playerid][pAmmo][10] = strval(Field[91]);
        PlayerInfo[playerid][pAmmo][11] = strval(Field[92]);
        PlayerInfo[playerid][pAmmo][12] = strval(Field[93]);
        PlayerInfo[playerid][pPayDay] = strval(Field[94]);
        PlayerInfo[playerid][pPayDayHad] = strval(Field[95]);
        PlayerInfo[playerid][pCDPlayer] = strval(Field[96]);
        PlayerInfo[playerid][pWins] = strval(Field[97]);
        PlayerInfo[playerid][pLoses] = strval(Field[98]);
        PlayerInfo[playerid][pTut] = strval(Field[99]);
        // IP [100]
        PlayerInfo[playerid][pWarns] = strval(Field[101]);
        PlayerInfo[playerid][pFuel] = strval(Field[102]);
        PlayerInfo[playerid][pHotdog] = strval(Field[103]);
        PlayerInfo[playerid][pMarried] = strval(Field[104]);
        PlayerInfo[playerid][pMarriedTo] = strval(Field[105]);
        PlayerInfo[playerid][pZastrzezony] = strval(Field[106]);
        PlayerInfo[playerid][pZezwolenie] = strval(Field[107]);
        PlayerInfo[playerid][pKartaNFZ] = strval(Field[108]);
        PlayerInfo[playerid][pKartaBank] = strval(Field[109]);
        PlayerInfo[playerid][pZastrzeg] = strval(Field[110]);
        PlayerInfo[playerid][pDowod] = strval(Field[111]);
        PlayerInfo[playerid][pKelner] = strval(Field[112]);
        PlayerInfo[playerid][pMogeBron] = strval(Field[113]);
        PlayerInfo[playerid][pDzwonek] = strval(Field[114]);
        PlayerInfo[playerid][pDzwiekSMS] = strval(Field[115]);
        PlayerInfo[playerid][pBMoge] = strval(Field[116]);
        PlayerInfo[playerid][pGPS] = strval(Field[117]);
        PlayerInfo[playerid][pBW] = strval(Field[118]);
        PlayerInfo[playerid][pBWTime] = strval(Field[119]);
        PlayerInfo[playerid][pTrener] = strval(Field[120]);
        PlayerInfo[playerid][pSztukaWalki] = strval(Field[121]);
        PlayerInfo[playerid][pStylChodzenia] = strval(Field[122]);
        PlayerInfo[playerid][pAdminInfo] = strval(Field[123]);
        PlayerInfo[playerid][pMask] = strval(Field[124]);
        PlayerInfo[playerid][pMaskuse] = strval(Field[125]);
        PlayerInfo[playerid][KillerID] = strval(Field[126]);
        PlayerInfo[playerid][KillerWeapon] = strval(Field[127]);
        PlayerInfo[playerid][Samochod2] = strval(Field[128]);
    	PlayerInfo[playerid][AlarmSamochodowy] = strval(Field[129]);
    	PlayerInfo[playerid][pVirtualWorld] = strval(Field[130]);
   		PlayerInfo[playerid][pSTDPlayer] = strval(Field[131]);
		PlayerInfo[playerid][pMatsHolding] = strval(Field[133]);
		PlayerInfo[playerid][pBeer] = strval(Field[134]);
		PlayerInfo[playerid][pWine] = strval(Field[135]);
		PlayerInfo[playerid][pSprunk] = strval(Field[136]);
		PlayerInfo[playerid][pJoint] = strval(Field[137]);
		PlayerInfo[playerid][pHotel] = strval(Field[138]);
    	PlayerInfo[playerid][pHRoom_locked] = strval(Field[139]);
    	PlayerInfo[playerid][pCrash] = strval(Field[140]);
    	PlayerInfo[playerid][pSpawn] = strval(Field[141]);
    	PlayerInfo[playerid][pHire] = strval(Field[142]);
    	PlayerInfo[playerid][pRadio] = strval(Field[143]);
    	PlayerInfo[playerid][pRadioOn] = strval(Field[144]);
    	PlayerInfo[playerid][pRadioChannel] = strval(Field[145]);
	    PlayerInfo[playerid][pFirstEnterGame] = strval(Field[146]);
	    PlayerInfo[playerid][pSArmour] = floatstr(Field[147]);
	    PlayerInfo[playerid][pRadioClient] = strval(Field[148]);
		mysql_free_result();
	}
	else
	{
        gPlayerLogTries[playerid] += 1;
        if(gPlayerLogTries[playerid] == 3)
	    {
	        ShowPlayerDialog(playerid,2,DIALOG_STYLE_MSGBOX,"Błąd","Podałeś nieprawidłowe hasło.\nPozostała Ci ostatnia prуba.","OK","Anuluj");
	    }
	    else
	    {
	    	ShowPlayerDialog(playerid,2,DIALOG_STYLE_MSGBOX,"Błąd","Podałeś nieprawidłowe hasło. Sprуbuj ponownie.","OK","Anuluj");
		}
        if(gPlayerLogTries[playerid] == 4)
		{
			SendClientMessage(playerid,COLOR_COM,"A-RP: Zostałeś zbanowany za 4 nieprawidłowe logowania.");
			ExBan(playerid,999,"4 nieprawidłowe logowania.");
		}
        return 1;
	}
	ResetPlayerMoney(playerid);
	GivePlayerMoney(playerid,PlayerInfo[playerid][pCash]);
	ConsumingMoney[playerid] = 1;
	if(PlayerInfo[playerid][pStatus] == -999) //autoban
	{
	    SendClientMessage(playerid,COLOR_COM,"A-RP: Twуj adres IP został zbanowany, Powуd: Ban Evading.");
		//Ban(playerid);
		ExBan(playerid,999,"Ban Evading.");
		return 1;
	}
	else if(PlayerInfo[playerid][pStatus] == -998) //autokick
	{
	    SendClientMessage(playerid,COLOR_COM,"A-RP: Zostałeś wyrzucony, Powуd: Zablokowane konto.");
		Kick(playerid);
		return 1;
	}
	else if(PlayerInfo[playerid][pStatus] == -100)
	{
	    SendClientMessage(playerid,COLOR_COM,"A-RP: Zostałeś wyrzucony, Powуd: Postać uśmiercona.");
	    Kick(playerid);
	    return 1;
	}

	else if(GetNumOfUserChars(PlayerInfo[playerid][pGID]) > 1)
	{
	    SendClientMessage(playerid,COLOR_COM,"A-RP: Nie możesz być zalogowany na dwуch postaciach rуwnocześnie.");
	    Kick(playerid);
	    return 1;
	}

	else	if(IsBannedUser(PlayerInfo[playerid][pGID]))
	{
	    SendClientMessage(playerid,COLOR_COM,"A-RP: Ta postać należy do zbanowanego konta.");
	    Kick(playerid);
		return 1;
	}
	PlayerInfo[playerid][pDonateRank] = GetDonate(PlayerInfo[playerid][pGID]);
	SendClientMessage(playerid,COLOR_COM," ");
	SendClientMessage(playerid,COLOR_COM," ");
	SendClientMessage(playerid,COLOR_COM," ");
	SendClientMessage(playerid,COLOR_COM," ");
	SendClientMessage(playerid,COLOR_COM," ");
	SendClientMessage(playerid,COLOR_COM," ");
	SendClientMessage(playerid,COLOR_COM," ");
	SendClientMessage(playerid,COLOR_COM," ");
	SendClientMessage(playerid,COLOR_COM," ");
	SendClientMessage(playerid,COLOR_COM," ");
	SendClientMessage(playerid,COLOR_COM," ");
	getdeatchtimer[playerid] = SetTimer("GetDeath",10000,1);
	PlayerInfo[playerid][pOnline] = 1;
	ClearChatbox(playerid, 10);
	format(string2, sizeof(string2), "A-RP: Witaj %s! Zalogowałeś się jako %s (ID: %d, UID: %d, GID: %d).",GetUser(PlayerInfo[playerid][pGID]),NickName(playerid),playerid,PlayerInfo[playerid][pSQLID],PlayerInfo[playerid][pGID]);
	SendClientMessage(playerid, COLOR_COM,string2);
	printf("%s zalogował się.",playername2);

	if (PlayerInfo[playerid][pDonateRank] == 1)
	{
		SendClientMessage(playerid, COLOR_COM,"A-RP: Posiadasz konto sponsora.");
	}
	if (PlayerInfo[playerid][pAdmin] > 0)
	{
		format(string2, sizeof(string2), "A-RP: Zainicjowano administratora poziomu %d.", PlayerInfo[playerid][pAdmin]);
		SendClientMessage(playerid, COLOR_COM,string2);
		format(string2, sizeof(string2), "Zalogowano na poziomie %d.", PlayerInfo[playerid][pAdmin]);
		AdmLog(playerid, string2);

	}
	if(gTeam[playerid] == 0)
	{
		gTeam[playerid] = 3;
	}
	else
	{
		gTeam[playerid] = PlayerInfo[playerid][pTeam];
	}
	AntiCheatProtect[playerid] = 5;
	gPlayerLogged[playerid] = 1;
	GetPlayerName(playerid,string2,sizeof(string2));
	UnderscoreToSpace(string2);
	for(new i = 0; i < MAX_PLAYERS; i++)
	{
		if(IsPlayerConnected(i))
 		{
  			if(PlayerInfo[i][pMaskuse] == 1)
    		{
     			//ShowPlayerNameTagForPlayer(playerid, i, 0);
	       	}
    	}
	}
	SetPlayerSkillLevel(playerid, WEAPONSKILL_PISTOL, 998);
	SetPlayerSkillLevel(playerid, WEAPONSKILL_MICRO_UZI, 0);
	SetPlayerSkillLevel(playerid, WEAPONSKILL_AK47, 0);
	if(Timestamp() - PlayerInfo[playerid][pLastUpdate] <= 1800) // 1800
	{
	    format(string2, sizeof(string2), "%s > Przywracanie pozycji", NickName(playerid));
        ShowPlayerDialog(playerid,8830,DIALOG_STYLE_MSGBOX,string2,"Opuszczono grę przed 30 minutami. Czy chcesz przywrуcić ostatnią pozycję?","Przywrуć","Anuluj");
	}
	else SpawnPlayer(playerid);
	return 1;
}


public MySQLFetchAcctSingle(sqlplayerid, sqlvalname[], sqlresult[])
{
	new query[128];
	format(query, sizeof(query), "SELECT %s FROM characters WHERE id = %d LIMIT 1", sqlvalname, sqlplayerid);
	mysql_query(query);
	mysql_store_result();
	if(mysql_fetch_row(sqlresult)==1)
	{
		return 1;
	}
	return 0;
}
I found in net this but I don't know how replace this with my code.

[code]#include <a_samp>
#include <a_mysql>
#include <sscanf>
#include <md5>

#define DIALOG_ID 12323
#define servname "Role Play"
#define tablename "users"
#define Login "Welcome to "servname"\nPlease write the password"
#define guidname "globuid"
#define name "nickname"
#define player_uid "player_uid"

new globaluid[MAX_PLAYERS];
new playeruid[MAX_PLAYERS];

public OnPlayerConnect(playerid) return ShowPlayerDialog(playerid, DIALOG_ID, DIALOG_STYLE_INPUT, ""servname" » Logowanie", Login, "Zaloguj", "Wyjdź");

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid == DIALOG_ID)
{
if(!response) return Kick(playerid);
new str[312];
new hash[256];
new salt[126];
format(str, sizeof(str), "SELECT "tablename"."guidname", "tablename"."player_uid", ipb_members.members_pass_salt FROM "tablename" JOIN ipb_members ON ipb_members.member_id = "tablename"."guidname" WHERE "tablename"."name" = '%s' LIMIT 1", NickName(playerid));
mysql_query(str);
mysql_store_result();
if(mysql_num_rows())
{
mysql_fetch_row_format(str);

sscanf(str, "p<|>dds[126]",
globaluid[playerid],
playeruid[playerid],
salt);

mysql_free_result();
}
else
{
GameTextForPlayer(playerid, "~n~~n~~n~~n~~r~Cant find global account", 2000, 5);
ShowPlayerDialog(playerid, DIALOG_ID, DIALOG_STYLE_INPUT, ""servname" » Login", Login, "Login", "Exit");
mysql_free_result();
return 1;
}
mysql_free_result();
format(hash, sizeof(hash), "%s%s", MD5_Hash(salt), MD5_Hash(inputtext));
format(str, sizeof(str), "SELECT "tablename".*, ipb_members.name, ipb_members.members_pass_hash FROM "tablename" JOIN ipb_members ON ipb_members.members_pass_hash = md5('%s') WHERE "tablename"."player_uid" = %d LIMIT 1", hash, playeruid[playerid]);
mysql_query(str);
mysql_store_result();
if(mysql_num_rows())
{
// Logged! ;]
}
else
{
GameTextForPlayer(playerid, "~n~~n~~n~~r~~h~Bad password !!",5000,5);
ShowPlayerDialog(playerid, DIALOG_ID, DIALOG_STYLE_INPUT, ""servname" » Login", Login, "Login", "Exit");
}
mysql_free_result();
}
return 1;
}

stock NickName(playerid)
{
new nick[MAX_PLAYER_NAME];
GetPlayerName(playerid, nick, sizeof(nick));
return nick;
}[code]
Reply


Messages In This Thread
MySQL - MD5+SALT - by Xaon - 05.03.2011, 13:47
Re: MySQL - MD5+SALT - by Xaon - 06.03.2011, 10:16

Forum Jump:


Users browsing this thread: 1 Guest(s)