Registration problem -
CrystalMethod - 17.03.2017
So working on a registration system. Problem is when I join my server, it says the account isn't registered, which is good because it isn't yet. So I enter a pass to register, it then tells me invalid then wants me to log in. I can just close out of the login menu then gain access to the server. Probably just gonna link up the close button to kick the player, but I just need the registration system working. Here's the bit of code and some screenshots. Still relatively new to pawn, learning some everyday.
Код:
public OnPlayerConnect(playerid)
{
new query[126], pName[MAX_PLAYER_NAME];
GetPlayerName(playerid, pName, sizeof(pName));
format(query, sizeof(query), "SELECT * FROM users WHERE name = '%s'", pName);
mysql_query(query);
mysql_store_result();
if(mysql_num_rows() == 1)
{
SendClientMessage(playerid, -1, "That username is registered!");
ShowPlayerDialog(playerid, 0, DIALOG_STYLE_INPUT, "Login", "Please log in with your password.", "Login", "Close");
}
else
{
SendClientMessage(playerid, -1, "That username is not registered. You may register it!");
ShowPlayerDialog(playerid, 0, DIALOG_STYLE_INPUT, "Register", "Register with your desired password.", "Register", "Close");
}
return 1;
}
Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
switch(dialogid)
{
case 0:
{
if(response)
{
new query[126], pName[MAX_PLAYER_NAME];
GetPlayerName(playerid, pName, sizeof(pName));
format(query, sizeof(query), "SELECT * FROM users WHERE name ='%s' AND password ='%s'", pName, inputtext);
mysql_query(query);
mysql_store_result();
if(mysql_num_rows() == 1)
{
SendClientMessage(playerid, -1, "You have successfully signed in!");
SpawnPlayer(playerid);
}
else
{
SendClientMessage(playerid, -1, "Incorrect password!");
ShowPlayerDialog(playerid, 0, DIALOG_STYLE_INPUT, "Login", "Please log in with your password.", "Login", "Close");
}
}
}
case 1:
{
if(response)
{
new query[126], pName[MAX_PLAYER_NAME];
GetPlayerName(playerid, pName, sizeof(pName));
format(query, sizeof(query), "INSERT INTO users VALUES ('%s', '%s')", pName, inputtext);
mysql_query(query);
SendClientMessage(playerid, -1, "You have registered!");
SpawnPlayer(playerid);
}
}
}
return 1;
}
IMAGE ONE
IMAGE TWO
IMAGE THREE
Re: Registration problem -
X337 - 17.03.2017
You made a mistake here:
Код:
ShowPlayerDialog(playerid, 0, DIALOG_STYLE_INPUT, "Register", "Register with your desired password.", "Register", "Close");
which should be:
Код:
ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "Register", "Register with your desired password.", "Register", "Close");
Before you continue further making your registration system, i would suggest you to use BlueG's MySQL plugin instead of StrickenKid's one. And also you have to hash your player's password.
Re: Registration problem -
CrystalMethod - 17.03.2017
So I've changed the zero to a one and that's working better.
I've got a problem now where when it says that the account is registered, nothing pops up in the database. If I leave then come back, it prompts me to register again.
Here's how accounts are logged in and saved.
Код:
stock LoginPlayer(playerid)
{
new query[126], pName[MAX_PLAYER_NAME];
GetPlayerName(playerid, pName, sizeof(pName));
format(query, sizeof(query), "SELECT * FROM users WHERE Name = '%s'", pName);
mysql_query(query);
mysql_store_result();
while(mysql_fetch_row_format(query, "|"))
{
mysql_fetch_field_row(Player[playerid][Name], "Name");
mysql_fetch_field_row(Player[playerid][Password], "Password");
}
SpawnPlayer(playerid);
}
stock SavePlayer(playerid)
{
new query[126], pName[MAX_PLAYER_NAME];
GetPlayerName(playerid, pName, sizeof(pName));
format(query, sizeof(query), "UPDATE users SET Name = '%s', Password = '%s' WHERE Name = '%s'", pName, Player[playerid][Password], pName);
mysql_query(query);
printf("Player ID %d (%s) has been saved", playerid, pName);
}
Re: Registration problem -
CrystalMethod - 17.03.2017
Apologies for the double post. Upon joining the server, the player's name does save in the database, but without a password. Passwords are (at least should be) saved using the code below.
Код:
stock RegisterPlayer(playerid, regpass[])
{
new query[256], EncryptedPass[130];
WP_Hash(EncryptedPass, sizeof(EncryptedPass), regpass);
format(query, sizeof(query), "INSERT INTO users (Name, Password) VALUES ('%s', '%s')", GetName(playerid), EncryptedPass);
mysql_query(query);
LoginPlayer(playerid);
return 1;
}
Код:
stock SavePlayer(playerid)
{
new query[356], EncryptedPass[130];
WP_Hash(EncryptedPass, sizeof(EncryptedPass), Player[playerid][Password]);
format(query, sizeof(query), "UPDATE users SET Name = '%s', Password = '%s'", GetName(playerid), Player[playerid][Password]);
mysql_query(query);
printf("Player ID %d (%s) has been saved", playerid, GetName(playerid));
}
Help here is appreciated.