MySQL Registration - Storing the hashed password to the end of the reg?
#1

Hi!

I'm just curious if there's a good way to store a password till the end of the registration. So what I'd like to do is basically store everything the person registeres throughout the registration process to the end of the registration, and then send a query to the database with all that information.

I bet there's plenty of better ways to deal with this, but I don't want to store any accounts that haven't been registered correctly. Meaning it would be perfect for me to store everything when the person is done with the registration. I'm new to both MySQL and pawn so don't kill me for asking these stupid questions. I do have plenty of mistakes in my code that I am unaware of (assuming), and therefore I'd love to get feedback and comments on how to do it correctly and more efficient - wether it's the way I save/load data or the pawn code in general.

This is how my registration should work as of right now (obviously doesn't due to problems with storing data):

- You enter a password, it gets hashed and that password should be stored to the end of the registration.
- After entering your password, you'll choose a gender (male or female) using msgbox, response or no response.
- Then you will have to write in the year your character was born (between year 1916 & 2006)
- After that you'll have to write in the origin of your character (text)

Then all the data should be stored into the database, as that is when you'll spawn in-game. Is this possible or is it a bad idea afterall? I decided to uplodate it to pastebin (easier to read the code): http://pastebin.com/FCWJt9pX

I also have some questions regarding how I should store the data in-game when e.g I change the skin of a player, should I store it automatically to the database (if yes, what's the best way to do it) or wait till the player disconnects? And how to avoid rollbacks when the server unexpectedly shuts down? Please come with suggestions!

And yes I am new to pawn and the way I find the way I dealt with dialogs quite confusing, so it's probably messed up and it doesn't work out properly. Also taking a MySQL course as we speak. Only the name, year and gender gets saved right now. The problem is most likely the way I try to store the password to the end of the registration.


Again, the code can be found here: http://pastebin.com/FCWJt9pX (if you need any more info etc let me know)
Reply
#2

OK, so if I read your post correctly, you want this behaviour:
  • show a series of dialogs
  • push everything to database at the end of a successful registration
Since you're working with multiple dialogs, you will have to store the values temporarily in the script.
Reply
#3

Quote:
Originally Posted by Freaksken
Посмотреть сообщение
OK, so if I read your post correctly, you want this behaviour:
  • show a series of dialogs
  • push everything to database at the end of the registration
You are correct. Is that a good idea? Want to prevent half-registered members. I know you can make them finish the dialogs they didn't, but I don't really want that. Want it all to be done at once.

Update: I tried to temporarily store the data, but apparently that didn't work out well haha. Any suggestions? Want it to be as efficient as possible.
Reply
#4

Quote:
Originally Posted by Hargrave
Посмотреть сообщение
You are correct. Is that a good idea? Want to prevent half-registered members. I know you can make them finish the dialogs they didn't, but I don't really want that. Want it all to be done at once.

Update: I tried to temporarily store the data, but apparently that didn't work out well haha. Any suggestions? Want it to be as efficient as possible.
Yes, it is possible to just not push a query if any part of the registration is invalid. I'll try to explain it a bit more:

Код:
//Globals
#define MAX_REGISTRATION_PASSWORD       128 + 1 //See Dialog input limit
#define MAX_REGISTRATION_ORIGIN         128 + 1 //See Dialog input limit
enum REGISTRATION_ENUM {
    PASSWORD[MAX_REGISTRATION_PASSWORD],
    bool:GENDER, //False = male, true = female
    YEAR,
    ORIGIN[MAX_REGISTRATION_ORIGIN]
}
new registrationInfo[MAX_PLAYERS][REGISTRATION_ENUM];

//OnPlayerConnect (reset variables before showing the dialogs)
format(registrationInfo[playerid][PASSWORD], MAX_REGISTRATION_PASSWORD, "");
registrationInfo[playerid][GENDER] = false;
registrationInfo[playerid][YEAR] = 0;
format(registrationInfo[playerid][ORIGIN], MAX_REGISTRATION_ORIGIN, "");

//OnDialogResponse
//Password dialog
//Successfull
format(registrationInfo[playerid][PASSWORD], MAX_REGISTRATION_PASSWORD, myHashFunction(inputtext));
//Unsuccessfull
kick or reshown dialog to try again
//Gender dialog
//Successfull
registrationInfo[playerid][GENDER] = response; //Female
//Unsuccessfull
registrationInfo[playerid][GENDER] = response; //Male
//Year dialog
//Successfull
registrationInfo[playerid][YEAR] = strval(inputtext);
//Unsuccessfull
kick or reshown dialog to try again
//Origin dialog
//Successfull
format(registrationInfo[playerid][ORIGIN], MAX_REGISTRATION_ORIGIN, inputtext);
push query
//Unsuccessfull
kick or reshown dialog to try again
If you would like me te rewrite the code you posted on pastebin, with the steps I posted above. Ask me and I will comment every step so you can learn something from it. If however you can figure it out on your own with the info I provided, glad I could help .
Reply
#5

Quote:
Originally Posted by Hargrave
Посмотреть сообщение
Hi!

I also have some questions regarding how I should store the data in-game when e.g I change the skin of a player, should I store it automatically to the database (if yes, what's the best way to do it) or wait till the player disconnects? And how to avoid rollbacks when the server unexpectedly shuts down? Please come with suggestions!
Hello Hargrave,
A few days ago i hit an idea about saving data within just a line wherever i want it to save. For example you have typed /myskins then selected a skin, after this selection the saving to the database is important as much as i know.
so i came with this idea that i must define few names and specify them in my stocks via switch function here is an example
PHP код:

#define Save_AccountInfo // where i'll save player's password, IP, Admin Level, GPCI etc..
#define Save_AccountValue // where i will save player's Bank Money, Kills, Deaths,Ratio etc..
#define Save_AccountPunishment // where i will save player's Banned, Kicked, Jailed, BannedBy,JailedBy etc..
#define Save_AccountGaming // where i will save player's RaceWon, DerbyWon, LMSWon, FallOutWon etc..
#define Save_AccountVIP // where i will save player's Vip, VipLevel, VipSkin, VipWeather etc.. 
And then i will make a stock just like this
PHP код:
static stock SaveData(playeriddatavalue)
{
    new 
query[250];
    switch (
datavalue)
    {
        case 
Save_AccountInfomysql_format(mysqlquerysizeof(query), "INSERT INTO `Accounts` ( `Username`, `Password`.... )");
        case 
Save_AccountValue:mysql_format(mysqlquerysizeof(query), "UPDATE `Accounts`  ....");
        case 
Save_AccountPunishment:mysql_format(mysqlquerysizeof(query), "UPDATE  `Accounts` ....");
        case 
Save_AccountGaming:mysql_format(mysqlquerysizeof(query), "UPDATE  `Accounts` ....");
        case 
Save_AccountVIP:mysql_format(mysqlquerysizeof(query), "UPDATE  `Accounts` ....");
          default: return 
0;
    }
    
mysql_tquery(mysqlquery);

And then i will use it as

PHP код:
CMD:myskin(playerid,params[])
{
    new 
skinid;
    if(
sscanf(params"i"skinid)) return    SendClientMessage(playerid, -1"- Error - USAGE: /Myskin [Skin ID]") ;
    if(
skinid || skinid 299) return SendClientMessage(playerid, -1"- Error - Invalid skin ID!");
    
SetPlayerSkin(playerid,skinid);
    
PlayerInfo[playerid][pVipSkin] = skinid;
    
SaveData(playeridSave_AccountVIP); // here just saved it
    
new str[128];
    
format(strsizeof(str),"- Vip - You changed your skin to skin ID %d!"skinid);
    
SendClientMessage(playerid, -1str);
    return 
1;

i know you may not like this but its the easiest way for me not to write same shit again and again.. and end it up with just 1 line

NOTE: its just a snippet... Don't go hard on me.
Reply
#6

Thanks for the help Freaksken, managed to work it out due to your help!
Looks like cool way to do it, however is it a smart and efficient way? I have absolutely no clue, therefore I am asking. Anyone else tried out that way of doing it? You know I'd like to use the best way of storing data from the start of so I don't have to go through the whole code once again within the next weeks to improve the way I store data.
Reply
#7

That depends if you want to relay on MySQL to store the password for you or server variables, you can easily make a table called pre_register and keep the name and chosen password in it, then push it from there to your main table, or keep it in server variables in a 2D array like pPass[MAX_PLAYERS][129];
I feel like first way is too much of a hassle, as it trades cpu for ram, although you could use threaded queries but even with 1000 MAX_PLAYERS that array won't be that big.


UPDATE: for easier dialog handling use this include https://sampforum.blast.hk/showthread.php?tid=475838
Reply
#8

I tend to use PVars for these sorts of short-lived temporary things. It seems silly to allocate a huge MAX_PLAYER array that isn't going to be used 99% of the time.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)