Raised This Month: $ Target: $400
 0% 

MqSql


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
NzGamers
Member
Join Date: Jul 2009
Old 10-07-2010 , 04:12   MqSql
Reply With Quote #1

I am currently coding a admin login plugin.

Im having trouble with mysql.

How can i load mysql and check if the user name and password matches any from the database?
NzGamers is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 10-07-2010 , 18:59   Re: MqSql
Reply With Quote #2

You will need to change the queries to match your table.

Unthreaded:
Code:
CheckLogin( iPlayer, const szUserName[ ], const szPassword[ ] ) {     new iError, szError[ 128 ];     new Handle:hDb = SQL_Connect( g_hSqlTuple, iError, szError, charsmax( szError ) );         if( hDb != Empty_Handle )     {         new Handle:hQuery = SQL_PrepareQuery( hDb, "SELECT COUNT(*) FROM users WHERE username = ^"%s^" AND password = ^"%s^";", szUserName, szPassword );                 if( !SQL_Execute( hQuery ) )         {             SQL_QueryError( hQuery, szError, charsmax( szError ) );             log_amx( "Error checking login: %s", szError );         }         else if( SQL_ReadResult( hQuery, 0 ) > 0 )         {             client_print( iPlayer, print_chat, "* Successfully logged in!" );         }         else         {             client_print( iPlayer, print_chat, "* Login failed!" );         }                 SQL_FreeHandle( hQuery );         SQL_FreeHandle( hDb );     }     else     {         log_amx( "Error connecting to SQL: %s", szError );     } }

Threaded:
Code:
CheckLogin( iPlayer, const szUserName[ ], const szPassword[ ] ) {     new szQuery[ 128 ];     formatex( szQuery, charsmax( szQuery ), "SELECT COUNT(*) FROM users WHERE username = ^"%s^" AND password = ^"%s^";", szUserName, szPassword );         new iData[ 1 ];     iData[ 0 ] = iPlayer;         SQL_ThreadQuery( g_hSqlTuple, "QueryCheckLogin", szQuery, iData, sizeof( iData ) ); } public QueryCheckLogin( iFailState, Handle:hQuery, szError[ ], iError, iData[ ], iDataSize, Float:flQueueTime ) {     switch( iFailState )     {         case TQUERY_CONNECT_FAILED:         {             log_amx( "Error connecting to SQL: %s", szError );         }         case TQUERY_QUERY_FAILED:         {             log_amx( "Error checking login: %s", szError );         }         case TQUERY_SUCCESS:         {             new iPlayer = iData[ 0 ];                         if( SQL_ReadResult( hQuery, 0 ) > 0 )             {                 client_print( iPlayer, print_chat, "* Successfully logged in!" );             }             else             {                 client_print( iPlayer, print_chat, "* Login failed!" );             }         }     } }
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!

Last edited by Exolent[jNr]; 10-07-2010 at 21:29.
Exolent[jNr] is offline
NzGamers
Member
Join Date: Jul 2009
Old 10-07-2010 , 19:24   Re: MqSql
Reply With Quote #3

ty.

this is my cmdLogin

PHP Code:
public cmdLogIn(id)
{
    if(!
g_bUserhasLogedIn[id])
    {
        new 
szArg[32];
        
read_argv(1szArgcharsmax(szArg));
        
        new 
szArg2[32];
        
read_argv(2szArg2charsmax(szArg2));
        
        if(
strlen(szArg) < 1)
        {
            
console_print(id"Usage: <user> <password>");
            return 
PLUGIN_HANDLED;
        }
        
        else if(
equal(szArgUSER) && equal(szArg2PASS))
        {
            
g_bUserhasLogedIn[id] = true;
            
remove_task(id);
            
console_print(id"[ LOGIN ] Login Successful. Enjoy your game");
            return 
PLUGIN_HANDLED;
        }
        
        else if(!
equal(szArgUSER) || !equal(szArg2PASS))
        {
            
g_bUserhasLogedIn[id] = false;
            
console_print(id"[ LOGIN ] Incorrect UserName or Password. You have %i seconds to login left"g_iLogInTimer[id]);
        }
    }
    
    return 
PLUGIN_HANDLED;

NzGamers is offline
NzGamers
Member
Join Date: Jul 2009
Old 10-07-2010 , 19:38   Re: MqSql
Reply With Quote #4

this is the version where i added the mysql. did i do it right?

PHP Code:
public cmdLogIn(id)
{
    if(!
g_bUserhasLogedIn[id])
    {
        new 
szArg[32];
        
read_argv(1szArgcharsmax(szArg));
        
        new 
szArg2[32];
        
read_argv(2szArg2charsmax(szArg2));
        
        if(
strlen(szArg) < 1)
        {
            
console_print(id"Usage: <user> <password>");
            return 
PLUGIN_HANDLED;
        }
        
        new 
szQuery128 ];
        
formatexszQuerycharsmaxszQuery ), "SELECT COUNT(*) FROM users WHERE username = ^"%s^" AND password = ^"%s^";"szArgszArg2 );
        
        new 
iData];
        
iData] = iPlayer;
        
        
SQL_ThreadQueryg_hSqlTuple"QueryCheckLogin"szQueryiDatasizeofiData ) );
    }
    
    return 
PLUGIN_HANDLED;
}

public 
QueryCheckLoginiFailStateHandle:hQueryszError[ ], iErroriData[ ], iDataSizeFloat:flQueueTime )
{
    switch( 
iFailState )
    {
        case 
TQUERY_CONNECT_FAILED:
        {
            
log_amx"Error connecting to SQL: %s"szError );
        }
        case 
TQUERY_QUERY_FAILED:
        {
            
log_amx"Error checking login: %s"szError );
        }
        case 
TQUERY_SUCCESS:
        {
            new 
iPlayer iData];
            
            if( 
SQL_NumResultshQuery ) )
            {
                
client_printiPlayerprint_chat"* Successfully logged in!" );
            }
            else
            {
                
g_bUserhasLogedIn[id] = false;
                
console_print(id"[ NS LOGIN ] Incorrect UserName or Password. You have %i seconds to login left"g_iLogInTimer[id]);
            }
        }
    }

NzGamers is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 10-07-2010 , 19:38   Re: MqSql
Reply With Quote #5

Did you need any more help? Because there is no SQL in that function.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
NzGamers
Member
Join Date: Jul 2009
Old 10-07-2010 , 19:40   Re: MqSql
Reply With Quote #6

Quote:
Originally Posted by Exolent[jNr] View Post
Did you need any more help? Because there is no SQL in that function.
yes plz. i posted another one above and u check it
NzGamers is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 10-07-2010 , 19:43   Re: MqSql
Reply With Quote #7

Nice copy/paste. You did not even try to understand the code.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
NzGamers
Member
Join Date: Jul 2009
Old 10-07-2010 , 19:44   Re: MqSql
Reply With Quote #8

Quote:
Originally Posted by Exolent[jNr] View Post
Nice copy/paste. You did not even try to understand the code.
yea. im not advance scripter. can u help fix that function i posted plz.
NzGamers is offline
NzGamers
Member
Join Date: Jul 2009
Old 10-07-2010 , 19:59   Re: MqSql
Reply With Quote #9

i got it now.

PHP Code:
// Check User and Password
public cmdLogIn(id)
{
    if(!
g_bUserhasLogedIn[id])
    {
        new 
szArg[32];
        
read_argv(1szArgcharsmax(szArg));
        
        new 
szArg2[32];
        
read_argv(2szArg2charsmax(szArg2));
        
        if(
strlen(szArg) < 1)
        {
            
console_print(id"Usage: login <user> <password>");
            return 
PLUGIN_HANDLED;
        }
        
        
CheckLogin(idszArgszArg2);
    }
    
    return 
PLUGIN_HANDLED;

NzGamers is offline
NzGamers
Member
Join Date: Jul 2009
Old 10-07-2010 , 21:28   Re: MqSql
Reply With Quote #10

PHP Code:
// Check User and Password
public cmdLogIn(id)
{
    if(!
g_bUserhasLogedIn[id])
    {
        new 
szArg[32];
        
read_argv(1szArgcharsmax(szArg));
        
        new 
szArg2[32];
        
read_argv(2szArg2charsmax(szArg2));
        
        if(
strlen(szArg) < 1)
        {
            
console_print(id"Usage: login <user> <password>");
            return 
PLUGIN_HANDLED;
        }
        
        
CheckLogin(idszArgszArg2);
    }
    
    return 
PLUGIN_HANDLED;
}

CheckLoginiPlayer, const szUserName[ ], const szPassword[ ] )
{
    new 
szQuery[128];
    
formatex(szQuerycharsmax(szQuery), "SELECT COUNT(*) FROM users WHERE username = ^"%s^" AND password = ^"%s^";"szUserNameszPassword);
    
    new 
iData[1];
    
iData[0] = iPlayer;
    
    
SQL_ThreadQuery(g_hSqlTuple"QueryCheckLogin"szQueryiDatasizeof(iData));
}

public 
QueryCheckLogin(iFailStateHandle:hQueryszError[], iErroriData[], iDataSizeFloat:flQueueTime)
{
    switch(
iFailState)
    {
        case 
TQUERY_CONNECT_FAILED:
        {
            
log_amx"Error connecting to SQL: %s"szError );
        }
        case 
TQUERY_QUERY_FAILED:
        {
            
log_amx"Error checking login: %s"szError );
        }
        case 
TQUERY_SUCCESS:
        {
            new 
iPlayer iData[0];
            
            if(
SQL_NumResults(hQuery))
            {
                
g_bUserhasLogedIn[iPlayer] = true;
                
remove_task(iPlayer);
                
console_print(iPlayer"[ LOGIN ] Login Successful. Enjoy your game");
                
client_printc(iPlayer"!g[ LOGIN ]!n Login !tSuccessful!n. Enjoy your game");
                return 
PLUGIN_HANDLED;
            }
            else
            {
                
g_bUserhasLogedIn[iPlayer] = false;
                
console_print(iPlayer"[ LOGIN ] Incorrect UserName or Password. You have %i seconds to login left"g_iLogInTimer[iPlayer]);
            }
        }
    }
    
    return 
PLUGIN_HANDLED;

when i enter the user and password and those user or password is wrong it still goes successfull even if the user and password it right. thats my problem right now
NzGamers is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 10:16.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode