• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Pawn] sqlite and inputtext
#1
I am trying to create an SQLite database, I only have three variables to keep it simple.



The problem is that the password is not saved unless I pass <inputtext> directly to the query.



Variables:



Code:
enum USER_DATA {

? ? USER_ID,

? ? USER_NICKNAME[MAX_PLAYER_NAME],

? ? USER_PASSWORD[20]

};



new gUserData[MAX_PLAYERS][USER_DATA];





Code working:





Code:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) {

? ? switch (dialogid) {

? ? ? ? case DIALOG_REGISTRATION: {

? ? ? ? ? ? if (!response) return Kick(playerid);



? ? ? ? ? ? if (!(3 <= strlen(inputtext) <= 20)) {

? ? ? ? ? ? ? ? SendClientMessage(playerid, -1, "Tu contrase?a debe tener entre 3 y 20 car?cteres");

? ? ? ? ? ? ? ? ShowPlayerDialog(playerid, DIALOG_REGISTRATION, DIALOG_STYLE_PASSWORD, "Register", "Type in a password below to register an account.", "Register", "Leave" );

? ? ? ? ? ? ? ? return 1;

? ? ? ? ? ? }



? ? ? ? ? ? new query[208], DBResult: result;

? ? ? ? ? ?

? ? ? ? ? ? format(query, sizeof query, "INSERT INTO users (nickname, password) VALUES ('%q', '%s')", gUserData[playerid][USER_NICKNAME], inputtext);



? ? ? ? ? ? db_query(db_handle, query);



? ? ? ? ? ? SendClientMessage(playerid, 0x00FF00FF, "[SERVER]: You have just registered to our server! You have been automatically logged in!");



? ? ? ? ? ? result = db_query(db_handle, "SELECT last_insert_rowid()");

? ? ? ? ? ? gUserData[playerid][USER_ID] = db_get_field_int(result);



? ? ? ? ? ? db_free_result(result);

? ? ? ? }

? ? }

? ? return 1;

}



Code isn't working:



Code:
gUserData[playerid][USER_PASSWORD] = inputtext[strlen(inputtext)];? ? ? ? ? ?



? ? ? ? ? ? format(query, sizeof query, "INSERT INTO users (nickname, password) VALUES ('%q', '%s')", gUserData[playerid][USER_NICKNAME], gUserData[playerid][USER_PASSWORD]);



The password field on the database is empty, and other values are ok. No error has given from the compiler.
  Reply
#2
If you're using YSI, just do this:

Code:
strcpy(gUserData[playerid][USER_PASSWORD], inputtext);

mysql_format (db_handle, query, sizeof query, "INSERT INTO users (nickname, password) VALUES ('%q', '%e')", gUserData[playerid][USER_NICKNAME], gUserData[playerid][USER_PASSWORD]);

It should work now.
Using Pawn.CMD?

If you're doing so, this is the very first sign that you absolutely shouldn't utilize your all powerful P-Code knowledge in any of the scripting discussion topics.
  Reply
#3
(2021-03-21, 05:45 PM)Pinch Wrote: If you're using YSI, just do this:



Code:
strcpy(gUserData[playerid][USER_PASSWORD], inputtext);



mysql_format (db_handle, query, sizeof query, "INSERT INTO users (nickname, password) VALUES ('%q', '%e')", gUserData[playerid][USER_NICKNAME], gUserData[playerid][USER_PASSWORD]);



It should work now.



Thank you! I am trying to add y_svar but the compiler throws an error.

Code:
C:\Projects\SAMP\Server\dependencies\YSI-Includes\YSI_Storage\y_svar\y_svar_ini.inc:122 (error) undefined symbol "INI_WriteArray"

Do you know how to fix it?



Code:
#define MODE_NAME "SavedText"

#include <YSI_Storage/y_svar>

I placed it after the "fixes" include. I also tried placing it in a place before "fixes" but it throws other even weirder errors.
  Reply
#4
Code:
gUserData[playerid][USER_PASSWORD] = inputtext[strlen(inputtext)];

That's your problem.

Code:
inputtext="Hello"

[0] = 'H'

[1] = 'e'

[2] = 'l'

[3] = 'l'

[4] = 'o'

[5] = '\0' EOS



strlen(inputtext) = 5;



inputtext[strlen(inputtext)] = inputtext[5] = '\0'

You're assigned EOS to the first element of gUserData[playerid][USER_PASSWORD], which results in an empty string. Just concatenate it to the array.

Code:
strcat(gUserData[playerid][USER_PASSWORD], inputtext, 20);



May I interest you? https://burgershot.gg/showthread.php?tid=1419
  Reply
#5
(2021-03-21, 08:25 PM)Bakr Wrote:
Code:
gUserData[playerid][USER_PASSWORD] = inputtext[strlen(inputtext)];?
That's your problem.
Code:
inputtext="Hello"
[0] = 'H'
[1] = 'e'
[2] = 'l'
[3] = 'l'
[4] = 'o'
[5] = '\0' EOS

strlen(inputtext) = 5;

inputtext[strlen(inputtext)] = inputtext[5] = '\0'
You're assigned EOS to the first element of gUserData[playerid][USER_PASSWORD], which results in an empty string. Just concatenate it to the array.
Code:
strcat(gUserData[playerid][USER_PASSWORD], inputtext, 20);

May I interest you? https://burgershot.gg/showthread.php?tid=1419

Thank you very much for the explanation! I found the code and what you have explained helpfully. The database stores the passwords now.

I'm going to take a look at samp-account, it looks interesting.
  Reply
#6
You should never store passwords in plain text form... always hash your passwords. It's a breach of both security and privacy.
  Reply
#7
(2021-03-24, 04:46 AM)Threshold Wrote: You should never store passwords in plain text form... always hash your passwords. It's a breach of both security and privacy.

Yes, I am currently using bcrypt. I just wanted to know the process of how to store a password and then implement bcrypt.
  Reply


Forum Jump: