MySQL storing player password
#1

Heya there, started learning MySQL and im trying to transfer my mode from dini to MySQL

The cache_get_field_content is used only on forwarded callbacks as much as I know

OnDialogResponse
PHP код:
else if(dialogid == 2) // Login
    
{
        if(
response)
        {
            new 
password[256], IP[16], password2[256], query[100];
            
WP_Hash(password2, sizeof(password2), inputtext);
            [
COLOR="Red"]password = cache_get_field_content([/COLOR]
            if(
strlen(inputtext) <= 0)
            {
                 
SendClientMessage(playerid, COLOR_LIGHTRED, "SERVER: {FFFFFF}You must enter a password to procceed.");
                 
ShowDialog(playerid, 2);
                 return 
1;
            }
            if(
strlen(inputtext) >= 256)
            {
                 
SendClientMessage(playerid, COLOR_LIGHTRED, "SERVER: {FFFFFF}Invalid Password.");
                 
ShowDialog(playerid, 2);
                 return 
1;
            }
            if(!
strcmp(password2, password, false))
            {
                
SendClientMessage(playerid, COLOR_LIME, "");
                
SendClientMessage(playerid, COLOR_LIME, "");
                
SendClientMessage(playerid, COLOR_RED, "SERVER: {FFFFFF}Login Successful");
                
format(PlayerInfo[playerid][pIP], 16, "%s", dini_Get(file, "IP"));
                
GetPlayerIp(playerid, IP, sizeof(IP));
                
dini_Set(file, "IP", IP);
                
PlayerInfo[playerid][pGender] = dini_Int(file, "Gender");
                
PlayerInfo[playerid][pAge] = dini_Int(file, "Age");
                if(!
PlayerInfo[playerid][pGender] || !PlayerInfo[playerid][pAge])
                {
                    
ShowDialog(playerid, 3);
                }
                else
                {
                    
mysql_format(mysql, query, sizeof(query), "SELECT * FROM `players` WHERE `Username` = '%e' LIMIT 1", RPNU(playerid));
                    
mysql_tquery(mysql, query, "OldToys", "i", playerid);
                    
mysql_tquery(mysql, query, "LoadToys", "i", playerid);
                }
            }
            else
            {
                
SendClientMessage(playerid, COLOR_LIGHTRED, "SERVER: {FFFFFF}Invalid password.");
                
ShowDialog(playerid, 2);
                return 
1;
            }
        }
        else
        {
            
SendClientMessage(playerid, COLOR_LIGHTRED, "SERVER: {FFFFFF}You have chosen to quit the server.");
            
Kick(playerid);
        }
    } 
In the red line, how can I store the player's password ? It's stored under the column Password, how can I get his row ?

NOTE: I have added an ID to the playerinfo enum (auto increase)
Can I use it to get the row ?
Reply
#2

cache_get_field_content(0, "Password", password);

You've got to do it by getting the password via a query:
PHP код:
new 
    
password[MAX_PLAYERS][256];
forward getpassword(playerid);
public 
getpassword(playerid) {
    
cache_get_field_content(0, "Password", password[playerid]);
    return 
1;
}
public 
OnPlayerConnect(playerid) {
    new 
query[80];
    
mysql_format(mysql, query, "SELECT * FROM players WHERE Username = '%e'", usernamehere);
    
mysql_tquery(mysql, query, "getpassword", "i", playerid);
    return 
1;
} 
Reply
#3

Yeah like I thought, no chance to get it without forwarding
Thanks
Reply
#4

There is a way of doing all that without callbacks by using sql.inc.

SQLite syntax for both the database types (SQLite or MySQL)
Reply
#5

Quote:
Originally Posted by Gammix
Посмотреть сообщение
There is a way of doing all that without callbacks by using sql.inc.

SQLite syntax for both the database types (SQLite or MySQL)
Good include indeed, seen it when I was browsing includes to use
Although let me finish the basic then I'll start shortening it
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)