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(password2sizeof(password2), inputtext);
            [
COLOR="Red"]password cache_get_field_content([/COLOR]
            if(
strlen(inputtext) <= 0)
            {
                 
SendClientMessage(playeridCOLOR_LIGHTRED"SERVER: {FFFFFF}You must enter a password to procceed.");
                 
ShowDialog(playerid2);
                 return 
1;
            }
            if(
strlen(inputtext) >= 256)
            {
                 
SendClientMessage(playeridCOLOR_LIGHTRED"SERVER: {FFFFFF}Invalid Password.");
                 
ShowDialog(playerid2);
                 return 
1;
            }
            if(!
strcmp(password2passwordfalse))
            {
                
SendClientMessage(playeridCOLOR_LIME"");
                
SendClientMessage(playeridCOLOR_LIME"");
                
SendClientMessage(playeridCOLOR_RED"SERVER: {FFFFFF}Login Successful");
                
format(PlayerInfo[playerid][pIP], 16"%s"dini_Get(file"IP"));
                
GetPlayerIp(playeridIPsizeof(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(playerid3);
                }
                else
                {
                    
mysql_format(mysqlquerysizeof(query), "SELECT * FROM `players` WHERE `Username` = '%e' LIMIT 1"RPNU(playerid));
                    
mysql_tquery(mysqlquery"OldToys""i"playerid);
                    
mysql_tquery(mysqlquery"LoadToys""i"playerid);
                }
            }
            else
            {
                
SendClientMessage(playeridCOLOR_LIGHTRED"SERVER: {FFFFFF}Invalid password.");
                
ShowDialog(playerid2);
                return 
1;
            }
        }
        else
        {
            
SendClientMessage(playeridCOLOR_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(mysqlquery"SELECT * FROM players WHERE Username = '%e'"usernamehere);
    
mysql_tquery(mysqlquery"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)