[Ajuda] Problema com salting
#2

PHP код:
/************************
*        INCLUDES        *
*************************/
#include <a_mysql>
/************************
*        NATIVES         *
*************************/
native IsValidVehicle(vehicleid);
/************************
*        MYSQL        *
*************************/
#define MYSQL_HOST "localhost" 
#define MYSQL_USER "root" 
#define MYSQL_DATABASE "sfrp" 
#define MYSQL_PASSWORD "" 
/************************
*        DEFINES         *
*************************/
#define SPAWN_X 10.0 
#define SPAWN_Y 10.0 
#define SPAWN_Z 14.0 
#define SPAWN_A 0.0 
/***************
     Colors
****************/
#define RED 0xFF0000FF
#define BLUE 0x00FF00FF
#define GREEN 0x0000FFFF
/***************
     Dialogs
****************/
#define RegDialog 0
#define LogDialog 1 
/************************
*         ENUMS            *
*************************/
enum playerInfo 

    
ID
    
Name[MAX_PLAYER_NAME], 
    
Password[129], 
    
IP[16], 
    
Admin
    
VIP
    
Money
    
Float:posX
    
Float:posY
    
Float:posZ
    
Float:posA 
}; 
new 
pInfo[MAX_PLAYERS][playerInfo];
/************************
*        FORWARDS        *
*************************/
forward DelayedKick(playerid);
forward OnAccountCheck(playerid);
forward OnAccountLoad(playerid);
forward OnAccountRegister(playerid);
/************************
*        VARIABLES        *
*************************/
new mysql;
public 
OnGameModeInit()
{
    
SetGameModeText("[Pre-Alpha] SF-RP 0.0.1");
    
AddPlayerClass(00000000000);
    
mysql_log(LOG_ALL); 
    
mysql mysql_connect(MYSQL_HOSTMYSQL_USERMYSQL_DATABASEMYSQL_PASSWORD); 
    if(
mysql_errno() != 0
    { 
        
printf("[MySQL] Failed to connect."); 
    } 
    else 
    { 
        
printf("[MySQL] Connected successfully"); 
    } 
    return 
1;
}  
public 
OnGameModeExit()
{
    
mysql_close(mysql);
    return 
1;
}
public 
OnPlayerConnect(playerid)
{
    
// Codigo de se o jogador nao tiver o nome RP й kickado
    
else
    {
        
TogglePlayerSpectating(playeridtrue); 
        new 
query[128];
        
mysql_format(mysqlquerysizeof(query), "SELECT `Password`, `ID` FROM `accounts` WHERE `Name` = '%e' LIMIT 1"PlayerName(playerid)); 
        
mysql_tquery(mysqlquery"OnAccountCheck""i"playerid); 
    }
    return 
1;
}
public 
OnPlayerDisconnect(playeridreason

    
SavePlayerStats(playerid);
    
ResetPlayerStats(playerid);
    return 
1

public 
OnDialogResponse(playeriddialogidresponselistiteminputtext[]) 

    switch(
dialogid
    { 
        case 
LogDialog
        { 
            if(!
response) return Kick(playerid); 
            
            new 
hashpass[64+1]; 
            
SHA256_PassHash(inputtext"ADAWAD11AWD41ASDA2L222KDH"hashpasssizeof(hashpass));
            
            if(!
strcmp(hashpasspInfo[playerid][Password], true)) 
            { 
                new 
query[100];
                
mysql_format(mysqlquerysizeof(query), "SELECT * FROM `accounts` WHERE `Name` = '%e' LIMIT 1"PlayerName(playerid)); 
                
mysql_tquery(mysqlquery"OnAccountLoad""i"playerid); 
            } 
            else 
            { 
                
SendClientMessage(playerid, -1"You have specified an incorrect password!"); 
                
ShowPlayerDialog(playeridLogDialogDIALOG_STYLE_PASSWORD"Login""Welcome player!\nYour account has been found in our database. Please fill in your password:""Login""Quit"); 
            } 
        } 
        case 
RegDialog
        { 
            if(!
response) return Kick(playerid);
            if(
strlen(inputtext) < 5
            { 
                
SendClientMessage(playerid, -1"Your password must at least contain more than 4 characters."); 
                
ShowPlayerDialog(playeridRegDialogDIALOG_STYLE_INPUT"Register""Welcome player!\nYour account has not been registered yet. Please fill in your desired password:""Register""Quit"); 
            }
            else
            {
                new 
query[512], playerip[16];
                
GetPlayerIp(playeridplayeripsizeof(playerip));
      
                new 
hashpass[64+1]; 
                
SHA256_PassHash(inputtext"ADAWAD11AWD41ASDA2L222KDH"hashpasssizeof(hashpass));
            
                
mysql_format(mysqlquerysizeof(query), "INSERT INTO `accounts` (`Name`, `Password`, `IP`, `Admin`, `VIP`, `Money`, `PosX`, `PosY`, `PosZ`, `PosA`) VALUES ('%e', '%e', '%e', 0, 0, 0, %f, %f, %f, %f)"PlayerName(playerid), hashpassplayeripSPAWN_XSPAWN_YSPAWN_ZSPAWN_A); 
                
mysql_tquery(mysqlquery"OnAccountRegister""i"playerid); 
            }
        } 
    } 
    return 
1;
}    
/************************
*        FUNCTIONS        *
*************************/
PlayerName(playerid)
{
    new 
name[MAX_PLAYER_NAME];
    
GetPlayerName(playeridnamesizeof(name));
    return 
name;
}
SavePlayerStats(playerid)
{
    new 
query[128], Float:pos[4];
    
GetPlayerPos(playeridpos[0], pos[1], pos[2]); 
    
GetPlayerFacingAngle(playeridpos[3]); 
    
mysql_format(mysqlquerysizeof(query), "UPDATE `accounts` SET `Money` = %d, `PosX` = %f, `PosY` = %f, `PosZ` = %f, `PosA` = %f WHERE `ID` = %d"
    
GetPlayerMoney(playerid), pos[0], pos[1], pos[2], pos[3], pInfo[playerid][ID]); 
    
mysql_tquery(mysqlquery""""); 
    return 
1;
}
ResetPlayerStats(playerid)
{
    for (new 
i=0isizeof(pInfo[]); i++)
    {
        
pInfo[playerid][playerInfo:i] = 0;
    }
    return 
1;
}
escape(string[])
{
    new 
esc_string[512];
    
mysql_real_escape_string(stringesc_stringmysqlsizeof(esc_string));
    return 
esc_string;
}
randomString(strDest[], strLen 30)
{
    while(
strLen--)
        
strDest[strLen] = random(2) ? (random(26) + (random(2) ? 'a' 'A')) : (random(10) + '0');
}
/************************
*        CALLBACKS       *
*************************/
public OnAccountCheck(playerid

    new 
rowsfields
    
cache_get_data(rowsfieldsmysql); 
    if(
rows
    { 
        
cache_get_field_content(0"Password"pInfo[playerid][Password], mysql130);
        
pInfo[playerid][ID] = cache_get_field_content_int(0"ID"); 
        
ShowPlayerDialog(playeridLogDialogDIALOG_STYLE_PASSWORD"Login""Welcome player!\nYour account has been found in our database. Please fill in your password:""Login""Quit"); 
    } 
    else 
    { 
        
ShowPlayerDialog(playeridRegDialogDIALOG_STYLE_INPUT"Register""Welcome player!\nYour account has not been registered yet. Please fill in your desired password:""Register""Quit"); 
    } 
    return 
1

public 
OnAccountLoad(playerid)

    
pInfo[playerid][Admin] = cache_get_field_content_int(0"Admin"); 
    
pInfo[playerid][VIP] = cache_get_field_content_int(0"VIP"); 
    
pInfo[playerid][Money] = cache_get_field_content_int(0"Money"); 
    
pInfo[playerid][posX] = cache_get_field_content_float(0"PosX"); 
    
pInfo[playerid][posY] = cache_get_field_content_float(0"PosY"); 
    
pInfo[playerid][posZ] = cache_get_field_content_float(0"PosZ"); 
    
pInfo[playerid][posA] = cache_get_field_content_float(0"PosA"); 
    
TogglePlayerSpectating(playeridfalse); 
    
GivePlayerMoney(playeridpInfo[playerid][Money]); 
    
SetSpawnInfo(playerid023pInfo[playerid][posX], pInfo[playerid][posY], pInfo[playerid][posZ], pInfo[playerid][posA], 000000); 
    
SpawnPlayer(playerid); 
    
SendClientMessage(playerid, -1"You have successfully logged in."); 
    return 
1
}  
public 
OnAccountRegister(playerid

    
pInfo[playerid][ID] = cache_insert_id(); 
    
printf("[Registration] New account registered. Account ID: [%d]"pInfo[playerid][ID]); 
    
TogglePlayerSpectating(playeridfalse); 
    
SetSpawnInfo(playerid023SPAWN_XSPAWN_YSPAWN_ZSPAWN_A000000); 
    
SpawnPlayer(playerid); 
    return 
1

Use a funcao SHA256_PassHash para fazer hash assim nao precisa de nenhum plugin extra e ja coloca o salt na propria funcao.

E a partir da versao 0.3.7 R2 use %q para fazer escape. ( NO SQLITE )
Reply


Messages In This Thread
Problema com salting - by Andre02 - 11.09.2015, 16:31
Re: Problema com salting - by PT - 11.09.2015, 18:13
Re: Problema com salting - by Nixtren - 11.09.2015, 23:37
Re: Problema com salting - by PT - 11.09.2015, 23:44
Re: Problema com salting - by Nixtren - 11.09.2015, 23:46
Re: Problema com salting - by Andre02 - 12.09.2015, 08:12

Forum Jump:


Users browsing this thread: 1 Guest(s)