stock MySQL_Register(playerid, passwordstring[])
{
new query1[256*2], pname[24];
new Year, Month, Day, Hour, Minute, Second;
getdate(Year, Month, Day);
gettime(Hour, Minute, Second);
WP_Hash(query1, 256*2, passwordstring);
new RegDate[128];
format(RegDate, 128, "%d:%d:%d - %d/%d/%d", Hour, Minute, Second, Day, Month, Year);
new Bannedby[20];
format(Bannedby, 20, "Not Banned");
GetPlayerName(playerid, pname, 24);
format(query1, sizeof(query1), "INSERT INTO playerdata (user, password, Scores, Cash, Admin, Deaths, Nopm, Muted, Vip, Warn, RegisterDate, Jailed, AdminActions, Cookies, Rank, VipTime, Class, PrototypesStolen, KillAsUsaTeam, KillAsGermanyTeam, KillAsItalyTeam, KillAsJapanTeam, KillAsMercTeam, KillAsMexicoTeam, IP) VALUES('%s', '%s', 0, 0, 0, 0, 0, 0, 0, 0, '%s', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '%s')", pname, passwordstring, RegDate, GetIP(playerid));
mysql_query(query1);
Logged[playerid] = 1;
WindowForPlayer(playerid, "You are now ~r~registered ~w~to Battlefield War Heroes! Enjoy playing!");
WelcomeDialog(playerid);
new echo[130];
new kname[24];
GetPlayerName(playerid, kname, 24);
format(echo,sizeof(echo),"0,3** System: %s (%d) (IP: %s) has registered a new account",pname,playerid,GetIP(playerid));
IRC_GroupSay(gGroupID, IRC_ACHANNEL, echo);
new admin[128];
format(admin,sizeof(admin),"** System: %s (%d) (%s) has registered a new account.",pname,playerid,GetIP(playerid));
SendMessageToAdmins(LIGHTBLUE,admin);
new txd[128];
format(txd,sizeof(txd),"%s (%d) (IP: %s) registered a new account",pname,playerid,GetIP(playerid));
TextDrawSetString(RegTxd, txd);
new welcome[130];
format(welcome, sizeof(welcome), "Welcome to Battlefield War Heroes, ~r~%s! Type ~r~/rules ~w~and ~r~/cmds ~w~for server info.",pname);
GameTextForPlayer(playerid,welcome,6000,4);
return 1;
}
stock MySQL_Login(playerid)
{
new query2[650], pname[24], savingstring[20];
WP_Hash(query2, 650, savingstring);
GetPlayerName(playerid, pname, 24);
format(query2, sizeof(query2), "SELECT Scores, Cash, Admin, Deaths, Nopm, Muted, Vip, Warn, RegisterDate, Jailed, AdminActions, Cookies, Rank, VipTime, Class, PrototypesStolen, KillAsUsaTeam, KillAsGermanyTeam, KillAsItalyTeam, KillAsJapanTeam, KillAsMercTeam, KillAsMexicoTeam FROM playerdata WHERE user = '%s'", pname);
mysql_query(query2);
mysql_store_result();
while(mysql_fetch_row_format(query2,"|"))
{
mysql_fetch_field_row(savingstring, "Scores"); SetPlayerScore(playerid, strval(savingstring));
mysql_fetch_field_row(savingstring, "Cash"); MoneyGiven[playerid] = strval(savingstring);
mysql_fetch_field_row(savingstring, "Admin"); PlayerInfo[playerid][Admin] = strval(savingstring);
mysql_fetch_field_row(savingstring, "Deaths"); PlayerInfo[playerid][Deaths] = strval(savingstring);
mysql_fetch_field_row(savingstring, "Nopm"); PlayerInfo[playerid][Nopm] = strval(savingstring);
mysql_fetch_field_row(savingstring, "Muted"); PlayerInfo[playerid][Muted] = strval(savingstring);
mysql_fetch_field_row(savingstring, "Vip"); PlayerInfo[playerid][Vip] = strval(savingstring);
mysql_fetch_field_row(savingstring, "Warn"); PlayerInfo[playerid][Warn] = strval(savingstring);
mysql_fetch_field_row(savingstring, "RegisterDate"); PlayerInfo[playerid][RegisterDate] = strval(savingstring);
mysql_fetch_field_row(savingstring, "Jailed"); PlayerInfo[playerid][Jailed] = strval(savingstring);
mysql_fetch_field_row(savingstring, "AdminActions"); PlayerInfo[playerid][AdminActions] = strval(savingstring);
mysql_fetch_field_row(savingstring, "Cookies"); PlayerInfo[playerid][Cookies] = strval(savingstring);
mysql_fetch_field_row(savingstring, "Rank"); PlayerInfo[playerid][Rank] = strval(savingstring);
mysql_fetch_field_row(savingstring, "VipTime"); PlayerInfo[playerid][VipTime] = strval(savingstring);
mysql_fetch_field_row(savingstring, "Class"); PlayerInfo[playerid][Class] = strval(savingstring);
mysql_fetch_field_row(savingstring, "PrototypesStolen"); PlayerInfo[playerid][PrototypesStolen] = strval(savingstring);
mysql_fetch_field_row(savingstring, "Exp"); PlayerInfo[playerid][Exp] = strval(savingstring);
mysql_fetch_field_row(savingstring, "Duty"); PlayerInfo[playerid][Duty] = strval(savingstring);
mysql_fetch_field_row(savingstring, "KillAsUsaTeam"); PlayerInfo[playerid][KillAsUsaTeam] = strval(savingstring);
mysql_fetch_field_row(savingstring, "KillAsGermanyTeam"); PlayerInfo[playerid][KillAsGermanyTeam] = strval(savingstring);
mysql_fetch_field_row(savingstring, "KillAsItalyTeam"); PlayerInfo[playerid][KillAsItalyTeam] = strval(savingstring);
mysql_fetch_field_row(savingstring, "KillAsJapanTeam"); PlayerInfo[playerid][KillAsJapanTeam] = strval(savingstring);
mysql_fetch_field_row(savingstring, "KillAsMercTeam"); PlayerInfo[playerid][KillAsMercTeam] = strval(savingstring);
mysql_fetch_field_row(savingstring, "KillAsMexicoTeam"); PlayerInfo[playerid][KillAsMexicoTeam] = strval(savingstring);
}
mysql_free_result();
JustLogged[playerid] = 1;
Logged[playerid] = 1;
UpdateStatsTextdraw(playerid);
SendClientMessage(playerid,red,"------------------------------------------------------");
new playername3[MAX_PLAYER_NAME];
GetPlayerName(playerid, playername3, sizeof(playername3));
new string[200],stringg[200];
format(string,sizeof(string),"* System: Welcome back {F70505}%s (%d) {FFFFFF} - Your stats have been restored.",playername3,playerid);
format(stringg,sizeof(stringg),"* Level: {F70505}%d {FFFFFF} - Score: {F70505} %d {FFFFFF} - Exp: {F70505}%d {FFFFFF}- CSCash: {F70505} %i -",PlayerInfo[playerid][Admin],PlayerInfo[playerid][Scores],PlayerInfo[playerid][Exp],GetPlayerMoney(playerid));
SCM(playerid,-1,string);
SCM(playerid,-1,stringg);
SendClientMessage(playerid,red,"------------------------------------------------------");
return 1;
}
You're using the same string for both the password hash and the query.
Use a separate string for the hash, max hash size is 128+1 |
new buff[129];
WP_Hash(buff, 129, passwordstring);
format(query1, sizeof(query1), "INSERT INTO playerdata (user, password, Scores, Cash, Admin, Deaths, Nopm, Muted, Vip, Warn, RegisterDate, Jailed, AdminActions, Cookies, Rank, VipTime, Class, PrototypesStolen, KillAsUsaTeam, KillAsGermanyTeam, KillAsItalyTeam, KillAsJapanTeam, KillAsMercTeam, KillAsMexicoTeam, IP) VALUES('%s', '%s', 0, 0, 0, 0, 0, 0, 0, 0, '%s', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '%s')", pname, buff, RegDate, GetIP(playerid));
password varchar(40) latin1_swedish_ci NULL |
[00:21:23] CMySQLHandler::Query(SELECT `user` FROM playerdata WHERE user = 'Face9000' AND password = SHA1('testpass')) - Successfully executed. [00:21:23] >> mysql_store_result( Connection handle: 1 ) [00:21:23] CMySQLHandler::StoreResult() - Result was stored. |
Now i can register and it asks me to login, but the same problem of first post. "Wrong password" even if is correct. lol
For more info, this is how password column is made: Looking in mysql log it says: Why is still in SHA1 even if i hashed it? |
Now i can register and it asks me to login, but the same problem of first post. "Wrong password" even if is correct. lol
|
if(dialogid == DIALOG_LOGIN)
{
if(!response)
{
SendClientMessage(playerid, COLOR_RED, "** To play you must be registered or logged in.");
KickTimer[playerid] = SetTimerEx("KickPlayer",200,false,"d",playerid);
}
if(response)
{
new query[200], pname[24], escapepass[100];
GetPlayerName(playerid, pname, 24);
mysql_real_escape_string(inputtext, escapepass);
format(query, sizeof(query), "SELECT `user` FROM playerdata WHERE user = '%s' AND password = SHA1('%s')", pname, escapepass);
mysql_query(query);
mysql_store_result();
new numrows = mysql_num_rows();
if(numrows == 1) MySQL_Login(playerid);
if(!numrows)
{
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, ""White"Please log-in", ""White"Welcome back to "Red""SERVER_NAME""White"!\n"White"In order to start playing, you have to log-in!\n\n"White"Please insert "Red"your"White" password below:", "Login", "Cancel");
GameTextForPlayer(playerid,"~w~Wrong ~r~password.",2000,6);
}
mysql_free_result();
}
}
if(dialogid == DIALOG_REGISTER)
{
if(response)
{
if(CheckInput(inputtext)) return SendClientMessage(playerid, 0x0000ff, "You cannot use this password.");
if(!strlen(inputtext) || strlen(inputtext) > 100)
{
SendClientMessage(playerid,COLOR_RED,"Please enter a password within the length of 1 - 100 characters.");
ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, ""White"Please register",""White"Welcome to "Red""SERVER_NAME""White"!\n"White"In order to start playing, you have to register!\n\n"White"Please insert a password below:", "Register", "Cancel");
}
else if(strlen(inputtext) > 0 && strlen(inputtext) < 100)
{
new escpass[100];
mysql_real_escape_string(inputtext, escpass);
MySQL_Register(playerid, escpass);
}
}
if(!response)
{
SendClientMessage(playerid, COLOR_RED, "** To play you must be registered or logged in.");
KickTimer[playerid] = SetTimerEx("KickPlayer",200,false,"d",playerid);
}
}
Emh hold on. Found why is still in SHA1.
Login dialog: pawn Код:
|
format(query, sizeof(query), "SELECT `user` FROM playerdata WHERE user = '%s' AND password = SHA1('%s')", pname, escapepass);
format(query, sizeof(query), "SELECT `user` FROM playerdata WHERE user = '%s' AND password = '%s'", pname, escapepass);
This forum requires that you wait 240 seconds between posts. Please try again in 19 seconds.
new query[217], buff[129];
WP_Hash(buff, 129, inputtext);
format(query, sizeof(query), "SELECT `user` FROM playerdata WHERE user = '%s' AND password = '%s'", pname, buff);