Password hashing and loading issue..
#1

Okay so my password hashes and saves correctly into the database however once a player is registered and can play and they log off and log back online it prompts them that there Password is incorrect however i've tested multiple times and that is not the case.

Код:
public OnPlayerRegister(name[])
{
	if(cache_get_row_count() < 1) return print("[ERROR] OnPlayerRegister returned 'rows' as '0'.");
	new password[129], string[64], ip[16];
	cache_get_field_content(0, "Pass", PlayerInfo[playerid][pPass], dbHandle, 129);
	print("[DEBUG onPlayerRegister main]");
	new playerid = FindPlayer(name);
	if(playerid != -1)
	{
		print("[DEBUG onPlayerRegister is online ]");
		SCM(playerid,COLOR_PLAGREEN,"Your account has been approved!");
		new hashpass[129];
		WP_Hash(hashpass, sizeof(hashpass), hashpass);
		format(query, sizeof(query), "INSERT INTO `users` (name, password, registered, origin, playerIP) VALUES ('%s', '%s', 0, 'None', '%s')", name, hashpass, ip);
		mysql_function_query(dbHandle, query, true, "OnPlayerCreateAccount", "d", playerid);
		format(PlayerInfo[playerid][pPass],129,"%s",hashpass);
	}
Код:
public OnPlayerCreateAccount(playerid)
{
	PlayerInfo[playerid][pDatabaseID] = cache_insert_id(dbHandle);
	Dialog_Show(playerid, Secret, DIALOG_STYLE_INPUT, ""EMBED_WHITE"Welcome"EMBED_WHITE"", ""EMBED_WHITE"Enter a security question.", "Continue", "Quit");
	return 1;
}
LOGIN DIALOG:
Код:
Dialog:Login(playerid, response, listitem, inputtext[])
{
    cache_get_field_content(0, "password", PlayerInfo[playerid][pPass], dbHandle, 129);
    if(response)
    {
		if(isnull(inputtext))
		{
			Dialog_Show(playerid, Login, DIALOG_STYLE_PASSWORD, ""EMBED_WHITE"Welcome"EMBED_WHITE"", loginMsg, "Login", "Cancel");
			return 1;
		}
		new hashpass[129];
		WP_Hash(hashpass, sizeof(hashpass), inputtext);
		if(!strcmp(hashpass, PlayerInfo[playerid][pPass]))
  		{
			format(query, sizeof(query), "SELECT * FROM `users` WHERE `name` = '%s' AND `password` = '%s' LIMIT 0,1", GetName(playerid), hashpass);
			mysql_function_query(dbHandle, query, true, "LoginPlayer", "i", playerid);
		}
		else
		{
			Dialog_Show(playerid, Login, DIALOG_STYLE_PASSWORD, ""EMBED_WHITE"Welcome"EMBED_WHITE"", loginMsg, "Login", "Cancel");
		}
	}
    else
    {
		Kick(playerid);
    }
    return 1;
}
REGISTER DIALOG:
Код:
Dialog:Register(playerid, response, listitem, inputtext[])
{
    if (response)
    {
		if(isnull(inputtext))
		{
			Dialog_Show(playerid, Register, DIALOG_STYLE_INPUT, ""EMBED_WHITE"Welcome"EMBED_WHITE"", msg, "Register", "Quit");
			return 1;
		}
		if(strlen(inputtext) < 6)
		{
			Dialog_Show(playerid, Register, DIALOG_STYLE_INPUT, ""EMBED_WHITE"Welcome"EMBED_WHITE"", msg, "Register", "Quit");
			return 1;
		}
		SetPVarInt(playerid, "Approve", 0);
		SetPVarString(playerid, "TempPassword", inputtext);
		SetPVarInt(playerid, "TutQuestAmount", 0);
		SetIntVar(playerid, "RegisterPart", 1);
		return CallRemoteFunction("TutorialAnswers","i",playerid);
    }
    else
    {
		Kick(playerid);
    }
    return 1;
}
Reply
#2

i think your password must be load from file to PlayerInfo[playerid][pPass] when player getting logged in so without loading your password you are matching with your account password so its giving incorrect message you must load your password without getting logged in.
Reply
#3

Can you possibly show an example code for me?
Reply
#4

The problem is you trying to load player password hash in OnDialogResponse callback which is incorrect.
Код:
Dialog:Login(playerid, response, listitem, inputtext[])
{
    cache_get_field_content(0, "password", PlayerInfo[playerid][pPass], dbHandle, 129);
Remove your login dialog response code, with this code:
Код:
Dialog:Login(playerid, response, listitem, inputtext[])
{
    if(response)
    {
		if(isnull(inputtext))
		{
			Dialog_Show(playerid, Login, DIALOG_STYLE_PASSWORD, ""EMBED_WHITE"Welcome"EMBED_WHITE"", loginMsg, "Login", "Cancel");
			return 1;
		}
		new hashpass[129];
		WP_Hash(hashpass, sizeof(hashpass), inputtext);
		format(query, sizeof(query), "SELECT * FROM `users` WHERE `name` = '%s' AND `password` = '%s' LIMIT 0,1", GetName(playerid), hashpass);
		mysql_function_query(dbHandle, query, true, "LoginPlayer", "i", playerid);
		
		Dialog_Show(playerid, Login, DIALOG_STYLE_PASSWORD, ""EMBED_WHITE"Welcome"EMBED_WHITE"", loginMsg, "Login", "Cancel");
	}
    else
    {
		Kick(playerid);
    }
    return 1;
}
and add checks in LoginPlayer function if row is exists.
Example:
Код:
public LoginPlayer(playerid)
{
	if(cache_get_row_count())
	{
		// Player inputted correct password
	}
	else
		Dialog_Show(playerid, Login, DIALOG_STYLE_PASSWORD, ""EMBED_WHITE"Welcome"EMBED_WHITE"", loginMsg, "Login", "Cancel"); // Player inputted wrong password
	return 1;
}
Reply
#5

Tried your code and now when i join i get "You are banned from this server" each time.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)