MYSQL help
#1

I have added this into my script, https://sampforum.blast.hk/showthread.php?tid=485633&page=11 .

But the problem is once i registered and then re-join and when i enter my password it said wrong password.

I have checked ppl replied there in this thread and did what they said. But still getting can't login. it says wrong password:

My code is here: if you need more code please let me know. Thanks

PHP код:
enum PDATA //We name our enumerator as PDATA (which stands for PlayerDATA). You can name it however you want.
{
    
IDs//Will be used later to store player's ID from database so we can use it anywhere later
    
Password[129], //We will load player's password into this varible from database
    
Admin//We will load player's admin level from database into this variable so we can use it anywhere later.
    
VIP//We will load player's VIP level from database into this variable so we can use it anywhere later.
    
Money//We will load player's money from database into this variable so we can use it anywhere later.
    
Float:posX//We will load player's X position from database into this variable so we can use it anywhere later.
    
Float:posY//We will load player's Y position from database into this variable so we can use it anywhere later.
    
Float:posZ //We will load player's Z from database into this variable so we can use it anywhere later.
}
new 
pInfo[MAX_PLAYERS][PDATA]; //Variable that stores enumerator above 
PHP код:
forward OnAccountCheck(playerid);
public 
OnAccountCheck(playerid)
{
    new 
rowsfields//a variable that will be used to retrieve rows and fields in the database.
    
cache_get_data(rowsfieldsmysql);//let's get the rows and fields from the database.
    
if(rows//if there is row
    
{//then
        
cache_get_field_content(0"Password"pInfo[playerid][Password], mysql129);
        
//we will load player's password into pInfo[playerid][Password] to be used in logging in
        
pInfo[playerid][IDs] = cache_get_field_content_int(0"IDs"); //now let's load player's ID into pInfo[playerid][ID] so we can use it later
        
printf("%s"pInfo[playerid][Password]); //OPTIONAL: Just for debugging. If it didn't show your password, then there must be something wrong while getting player's password
        
ShowPlayerDialog(playeriddloginDIALOG_STYLE_INPUT"Login""In order to play, you need to login""Login""Quit"); //And since we found a result from the database, which means, there is an account; we will show a login dialog
    
}
    else 
//if we didn't find any rows from the database, that means, no accounts were found
    
{
        
ShowPlayerDialog(playeriddregisterDIALOG_STYLE_INPUT"Register""In order to play, you need to register.""Register""Quit");
        
//So we show them a dialog register
    
}
    return 
1;

PHP код:
public OnDialogResponse(playeriddialogidresponselistiteminputtext[])
{
    switch(
dialogid)
    {
        case 
dlogin//login dialog
        
{
            if(!
responseKick(playerid); //if they clicked Quit, we will kick them
            
new hpass[129]; //for password hashing
            
new query[100]; // for formatting our query.
            
WP_Hash(hpass129inputtext); //hashing inputtext
            
if(!strcmp(hpasspInfo[playerid][Password])) //remember we have loaded player's password into this variable, pInfo[playerid][Password] earlier. Now let's use it to compare the hashed password with password that we load
            
//if the hashed password matches with the loaded password from database
                
mysql_format(mysqlquerysizeof(query), "SELECT * FROM `players` WHERE `Username` = '%e' LIMIT 1"Name[playerid]);
                
//let's format our query
                //We select all rows in the table that has your name and limit the result to 1
                
mysql_tquery(mysqlquery"OnAccountLoad""i"playerid);
                
//lets execute the formatted query and when the execution is done, a callback OnAccountLoad will be called
                //You can name the callback however you like
            
}
            else 
//if the hashed password didn't match with the loaded password(pInfo[playerid][Password])
            
{
                
//we tell them that they have inserted a wrong password
                
ShowPlayerDialog(playeriddloginDIALOG_STYLE_INPUT"Login""In order to play, you need to login\nWrong password!""Login""Quit");
            }
        }
        case 
dregister//register dialog
        
{
            if(!
response) return Kick(playerid); //if they clicked Quit, we will kick them
            
if(strlen(inputtext) < 6) return ShowPlayerDialog(playeriddregisterDIALOG_STYLE_INPUT"Register""In order to play, you need to register.\nYour password must be at least 6 characters long!""Register""Quit");
            
//strlen checks a lenght of a string. so if player types their password that is lower than 6, we tell them; Your password must be at least 6 characters long!
            
new query[300];
            
WP_Hash(pInfo[playerid][Password], 129inputtext); //hashing inputtext
            
mysql_format(mysqlquerysizeof(query), "INSERT INTO `players` (`Username`, `Password`, `IP`, `Admin`, `VIP`, `Money`, `PosX` ,`PosY`, `PosZ`) VALUES ('%e', '%s', '%s', 0, 0, 0, 0.0, 0.0, 0.0)"Name[playerid], pInfo[playerid][Password], IP[playerid]);
            
//Now let's create a new row and insert player's information in it
            
mysql_tquery(mysqlquery"OnAccountRegister""i"playerid);
            
//let's execute the query
        
}
    }
    return 
1;

Reply


Messages In This Thread
MYSQL help - by STONEGOLD - 11.06.2015, 21:33
Re: MYSQL help - by STONEGOLD - 11.06.2015, 21:49

Forum Jump:


Users browsing this thread: 1 Guest(s)