Burgershot
  • Home
  • Members
  • Team
  • Help
  • Search
  • Register
  • Login
  • Home
  • Members
  • Help
  • Search
Burgershot SA-MP Pawn Scripting [Pawn] sqlite and inputtext

 
  • 0 Vote(s) - 0 Average
Pawn sqlite and inputtext
robertocaribbean
Offline

Burgershot Member
Posts: 27
Threads: 8
Joined: Aug 2020
Reputation: 0
Location: Argentina
#1
2021-03-21, 05:42 PM
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.
Pinch
Offline

Burgershot Member
Posts: 391
Threads: 19
Joined: Apr 2019
Reputation: 22
Location: Belgrade, Serbia
#2
2021-03-21, 05:45 PM (This post was last modified: 2021-03-21, 05:48 PM by Pinch.)
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.
robertocaribbean
Offline

Burgershot Member
Posts: 27
Threads: 8
Joined: Aug 2020
Reputation: 0
Location: Argentina
#3
2021-03-21, 06:37 PM
(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.
Bakr
Offline

Burgershot Member
Posts: 14
Threads: 2
Joined: Oct 2020
Reputation: 6
Location: United States
#4
2021-03-21, 08:25 PM
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
robertocaribbean
Offline

Burgershot Member
Posts: 27
Threads: 8
Joined: Aug 2020
Reputation: 0
Location: Argentina
#5
2021-03-21, 08:50 PM (This post was last modified: 2021-03-21, 08:52 PM by robertocaribbean.)
(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.
Threshold
Offline

Burgershot Member
Posts: 1
Threads: 0
Joined: Dec 2019
Reputation: 0
Location: Australia
#6
2021-03-24, 04:46 AM
You should never store passwords in plain text form... always hash your passwords. It's a breach of both security and privacy.
robertocaribbean
Offline

Burgershot Member
Posts: 27
Threads: 8
Joined: Aug 2020
Reputation: 0
Location: Argentina
#7
2021-03-24, 02:14 PM (This post was last modified: 2021-03-24, 02:29 PM by robertocaribbean.)
(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.
« Next Oldest | Next Newest »



  • View a Printable Version
  • Subscribe to this thread
Forum Jump:

© Burgershot - Powered by our Community and MyBB Original Theme by Emerald

Linear Mode
Threaded Mode