Password -
saffierr - 02.01.2016
When I finished this register login system I barely faced any problems.
Now, when the player registers to the server, his password gets hashed, but whenever the player leaves the hashed password gets the variable "0"...
system
PHP код:
public OnPlayerDisconnect(playerid, reason)
{
new string[75], pName[MAX_PLAYER_NAME];
GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
format(string, sizeof string, "%s has left the server.", pName);
SendClientMessageToAll(COLOR_GREY, string);
new INI:File = INI_Open(UserPath(playerid));
INI_SetTag(File, "PlayerData");
INI_WriteInt(File, "Password", PlayerInfo[playerid][Password]);
INI_WriteInt(File, "Admin", PlayerInfo[playerid][AdminLevel]);
INI_WriteInt(File, "Money", PlayerInfo[playerid][Money]);
INI_WriteInt(File, "Vip", PlayerInfo[playerid][VipLevel]);
INI_WriteInt(File, "Mechanic", PlayerInfo[playerid][Mechanic]);
INI_WriteInt(File, "SupportMember", PlayerInfo[playerid][SupportMember]);
INI_WriteInt(File, "Hitman", PlayerInfo[playerid][Hitman]);
INI_WriteInt(File, "Saaf", PlayerInfo[playerid][Saaf]);
INI_WriteInt(File, "Sapd", PlayerInfo[playerid][Sapd]);
INI_WriteInt(File, "Drivinglicense", PlayerInfo[playerid][Drivinglicense]);
INI_Close(File);
PHP код:
public OnDialogResponse()
if(dialogid==6)
{
if(response == 0)
{
SendClientMessage(playerid, COLOR_RED, "You have been kicked automatically.");
SetTimerEx("DelayedKick", 50, false, "i", playerid);
Kick(playerid);
}
if(response == 1)
{
if(strlen(inputtext) < 3) return SendClientMessage(playerid, COLOR_RED, "Error: You must create a password with atleast 3 characters.");
//ShowPlayerDialog(playerid, RegisterDialog, DIALOG_STYLE_PASSWORD, "Xtreme Gaming Freeroam/Roleplay - Registration", "Xtreme Gaming Freeroam/Roleplay - Fill a password to register", "Register", "Leave");
new INI:File = INI_Open(UserPath(playerid));
INI_SetTag(File, "PlayerData");
INI_WriteInt(File, "Password", udb_hash(inputtext));
INI_WriteInt(File, "Admin", 0);
INI_WriteInt(File, "Money", 0);
INI_WriteInt(File, "Vip", 0);
INI_WriteInt(File, "Mechanic", 0);
INI_WriteInt(File, "SupportMember", 0);
INI_WriteInt(File, "Hitman", 0);
INI_WriteInt(File, "Saaf", 0);
INI_WriteInt(File, "Sapd", 0);
INI_WriteInt(File, "Drivinglicense", 0);
INI_Close(File);
SetSpawnInfo(playerid, 0, 23, -2654.2371,608.3632,14.4531,358.4422, 0, 0, 0, 0, 0, 0);
SpawnPlayer(playerid);
}
}
if(dialogid==7)
{
if(response == 0)
{
SendClientMessage(playerid, COLOR_RED, "You have been kicked automatically.");
SetTimerEx("DelayedKick", 50, false, "i", playerid);
Kick(playerid);
}
if(response == 1)
{
if(udb_hash(inputtext) == PlayerInfo[playerid][Password])
{
new string[75];
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
GivePlayerMoney(playerid, PlayerInfo[playerid][Money]);
format(string, sizeof string, "%s has succesfully registered to our server!", PlayerName(playerid));
ShowPlayerDialog(playerid, LoginDialog, DIALOG_STYLE_PASSWORD, "Xtreme Gaming Freeroam/Roleplay - Login", "Xtreme Gaming Freeroam/Roleplay - Enter your password to login", "Login", "Leave");
SendClientMessage(playerid, -1, "Your account has been succesfully restored.");
}
else
{
SendClientMessage(playerid, COLOR_RED, "Error: Incorrect password.");
ShowPlayerDialog(playerid, LoginDialog, DIALOG_STYLE_PASSWORD, "Xtreme Gaming Freeroam/Roleplay - Login", "Xtreme Gaming Freeroam/Roleplay - Enter your password to login", "Login", "Leave");
}
}
}
PHP код:
forward LoadUser_data(playerid, name[], value[]);
public LoadUser_data(playerid, name[], value[])
{
INI_Int("Password", PlayerInfo[playerid][Password]);
INI_Int("Admin", PlayerInfo[playerid][AdminLevel]);
INI_Int("Money", PlayerInfo[playerid][Money]);
INI_Int("Vip", PlayerInfo[playerid][VipLevel]);
INI_Int("Mechanic", PlayerInfo[playerid][Mechanic]);
INI_Int("SupportMember", PlayerInfo[playerid][SupportMember]);
INI_Int("Hitman", PlayerInfo[playerid][Hitman]);
INI_Int("Saaf", PlayerInfo[playerid][Saaf]);
INI_Int("Sapd", PlayerInfo[playerid][Sapd]);
INI_Int("Drivinglicense", PlayerInfo[playerid][Drivinglicense]);
return 1;
}
stock UserPath(playerid)
{
new string[128], pName[MAX_PLAYER_NAME];
GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
format(string, sizeof string, "/Users/%s.txt", pName);
return string;
}
Re: Password -
AndySedeyn - 03.01.2016
Don't use udb_hash. You're probably saving it somewhere outside the register dialog/command. Or you're not correctly saving it.
I just updated a tutorial about y_ini and Whirlpool:
http://forum.sa-mp.com/showthread.ph...37#post3635637
Re: Password -
saffierr - 03.01.2016
I used to use MD5, is that good?
PHP код:
stock HashPassword(pass[])
{
new passwd[129], wp;
format(passwd, sizeof passwd, MD5_Hash(pass));
while(wp++ < 2468)
{
format(passwd, sizeof passwd, MD5_Hash(passwd));
}
return passwd;
}
Note I have posted my register system, take a look please.
Re: Password -
AndySedeyn - 03.01.2016
Just load the player's data once under OnPlayerConnect after resetting all the variables. There's no need to do it twice. Get rid of the udb_hash algorithm and use something more secure such as Whirlpool. I'm not familiar with using MD5 in PAWN but take a look at this post:
https://sampforum.blast.hk/showthread.php?tid=68237
EDIT:
The size of that string variable in the UserPath function can't exceed 36 characters. The maximum length of a player's name is 24 characters (20 actually) and your path won't change either. Count both lengths up and you get 34 or 35. So you're wasting over 80 bits (= 240 bytes or 0,240 kB of wasted memory).