Password to MySQL
#1

Hello! I have been trying to create a script that enters password with Whirlpool and other details into mySQL on registration. All other information is input to the database except the password field that remains blank.

Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
	if (dialogid == DIALOG_REGISTER)
	{
	    if (response)
	    {
	        if(strlen(inputtext) < 11 || strlen(inputtext) > 29 )
	        {
	            ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Register", ""RED"Your password must be between 11 and 29 characters long.\n"WHITE"Choose and enter a password:", "Register", "Quit");
			}
			else
			{
  				new query[150];
	  			new playerName[MAX_PLAYER_NAME];
				GetPlayerName(playerid, playerName, sizeof(playerName));
  				WP_Hash(PlayerInfo[playerid][Password], 129, inputtext);
  				
				mysql_format(dbHandle, query, sizeof(query), "INSERT INTO `players` (`Name`, `Password`, `Cash`) VALUES ('%s', '%s', %d)", playerName, PlayerInfo[playerid][Password], starterCash);
				mysql_tquery(dbHandle, query, "RegisterAccount", "i", playerid);
			}
	    }
	    else
	    {
	        Kick(playerid);
	    }
	}
	return 1;
}
Reply
#2

Keep in mind though that the query itself without specifiers is 68 characters + 128 characters from hash + 24 characters for name + (at least) 9 characters for the cash + 1 for NULL = 230 characters.
It would fail because the size is not long enough.

Can you post the table's structure for column "Password"?

There are also default values so when inserting a new row, you won't have to specify the cash (if it is a constant) which is very useful and also reduces the size of the query.
Reply
#3

I've fixed the password in the database, but now I cannot get database information to save into variables.
The "RegisterAccount" function doesn't seem to write to variables properly.

Game mode is here

Reply
#4

The size of "Password" in players table is 29 instead of 129. You may as well change it to CHAR(128) as it's a fixed-length string.

---

About the script:

- In "PlayerData" enum, you have to make "Name" and "Password" strings as you currently have them as an integers:
pawn Код:
// in the enumerator:
Name[MAX_PLAYER_NAME],
Password[129],
Since you have "Name", you can get the player's name once on connect so you won't need to keep calling GetPlayerName with a local string.

pawn Код:
// OnPlayerConnect:
GetPlayerName(playerid, PlayerInfo[playerid][Name], MAX_PLAYER_NAME);

// you can use "PlayerInfo[playerid][Name]" as argument in format/mysql_format now.
- Reset player-arrays on connect.

- You don't have the login part correct yet but you are trying to load them in the same callback that is used to retrieve the the unique ID. In "RegisterAccount", you only need:
pawn Код:
PlayerInfo[playerid][ID] = cache_insert_id();
Time to login the player. First of all, you are selecting the "ID" and "Name" from the database when it should have been the "ID" and "Password" instead. In "CheckAccount", you need to store the ID and the password to the variables and compare the passwords in OnDialogResponse. If they do match, execute a query that selects all the data and retrieve the data to store them to variables.

However, I recommend to load the data once (if there are not many columns). A good example that also uses race condition check can be found here: https://raw.githubusercontent.com/pB...stem-cache.pwn
Reply
#5

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
The size of "Password" in players table is 29 instead of 129. You may as well change it to CHAR(12 as it's a fixed-length string.

---

About the script:

- In "PlayerData" enum, you have to make "Name" and "Password" strings as you currently have them as an integers:
pawn Код:
// in the enumerator:
Name[MAX_PLAYER_NAME],
Password[129],
Since you have "Name", you can get the player's name once on connect so you won't need to keep calling GetPlayerName with a local string.

pawn Код:
// OnPlayerConnect:
GetPlayerName(playerid, PlayerInfo[playerid][Name], MAX_PLAYER_NAME);

// you can use "PlayerInfo[playerid][Name]" as argument in format/mysql_format now.
- Reset player-arrays on connect.

- You don't have the login part correct yet but you are trying to load them in the same callback that is used to retrieve the the unique ID. In "RegisterAccount", you only need:
pawn Код:
PlayerInfo[playerid][ID] = cache_insert_id();
Time to login the player. First of all, you are selecting the "ID" and "Name" from the database when it should have been the "ID" and "Password" instead. In "CheckAccount", you need to store the ID and the password to the variables and compare the passwords in OnDialogResponse. If they do match, execute a query that selects all the data and retrieve the data to store them to variables.

However, I recommend to load the data once (if there are not many columns). A good example that also uses race condition check can be found here: https://raw.githubusercontent.com/pB...stem-cache.pwn
Thank you so much. +rep
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)