Raised This Month: $ Target: $400
 0% 

I'm having some problems. I need your help.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
duydangle
Senior Member
Join Date: May 2010
Old 08-11-2010 , 10:28   I'm having some problems. I need your help.
Reply With Quote #1

I'm having some problems. I'm making a plugin, a registered system. You have to register to play on the server. That's like a username/password system. But I'm having some errors (Check the attachment). Take it a look, thank you so much.

Code:
#include <sourcemod>

new Handle:db

public Plugin:myinfo =
{
    name = "User Register System",
    author = "Mucno, duydangle",
    description = "A verify system.",
    version = "1.0",
    url = ""
}

new const String:AUTHMETHOD_RESTRICT[] = "default"

public OnPluginStart()
{
    CreateAuthMethod(AUTHMETHOD_RESTRICT)
    decl String:error[255]

    if (SQL_CheckConfig("admins"))
    {
        db = SQL_Connect("admins", true, error, sizeof(error))
    } else {
        db = SQL_Connect("default", true, error, sizeof(error))
    }

    if (db == INVALID_HANDLE)
    {
        LogError("Could not connect to database \"default\": %s", error)
        return
    }
}

public OnClientPutInServer(Client)
{
    new Handle:hQuery1
    new Handle:hQuery2
    new bool:FoundName = false
    new bool:FoundPass = false
    new String:Password[36],String:ClientPassword[36]
    new String:Name[36],String:ClientName[36]
    GetClientInfo(Client,"_name",ClientName,sizeof(ClientName))
    GetClientInfo(Client,"_pw",ClientPassword,sizeof(ClientPassword))
    hQuery1 = SQL_Query(db,"SELECT name FROM verifysystem")
    while ( SQL_FetchRow(hQuery1) )
        {
        SQL_FetchString(hQuery1,0,Name,sizeof(Name))
        if(StrEqual(Name,ClientName,false))
            FoundName = true
        }
    if(FoundName)
    {
        hQuery2 = SQL_Query(db,"SELECT password FROM verifysystem Where name = ClientName")
        while ( SQL_FetchRow(hQuery2) )
            {
                SQL_FetchString(hQuery2,0,Password,sizeof(Password))
                if(StrEqual(Password,ClientPassword,false))
            FoundPass = true
            }
    }
    if (FoundPass == false)
    {
        KickClient(Client,"You don't have access to this server")
    }
    CloseHandle(hQuery1)
    CloseHandle(hQuery2)

}
//A friend told me that the problem in this:

Code:
 hQuery2 = SQL_Query(db,"SELECT password FROM verifysystem WHERE name = ClientName")
He said SQL_Query can't understand ClientName's value.

//sorry for my bad English.
Attached Thumbnails
Click image for larger version

Name:	Capture.PNG
Views:	136
Size:	22.4 KB
ID:	71497  
Attached Files
File Type: sp Get Plugin or Get Source (verifysystem.sp - 354 views - 1.7 KB)
duydangle is offline
duydangle
Senior Member
Join Date: May 2010
Old 08-11-2010 , 10:31   Re: I'm having some problems. I need your help.
Reply With Quote #2

It's just a draft, and it's being developed. Take it a look. I appreciate you guys so much.

//My table has 3 colums: ID (auto-number), Name and Password.

Last edited by duydangle; 08-11-2010 at 10:34.
duydangle is offline
Leonardo
Veteran Member
Join Date: Feb 2010
Location: 90's
Old 08-11-2010 , 10:35   Re: I'm having some problems. I need your help.
Reply With Quote #3

PHP Code:
new String:query[256];
new 
Handle:result;
Format(querysizeof(query), "SELECT `password` FROM `verifysystem` WHERE `name` = '%s'"ClientName);
if((
result SQL_Query(db,query)) == INVALID_HANDLE)
{
    
PrintToServer("[DB Error] Invalid Query");
    
CloseHandle(result);
}
else
{
    
// do what you want

__________________

Last edited by Leonardo; 08-11-2010 at 10:43.
Leonardo is offline
duydangle
Senior Member
Join Date: May 2010
Old 08-11-2010 , 12:43   Re: I'm having some problems. I need your help.
Reply With Quote #4

Thank you so much. Problem solved, I'm developing its features
duydangle is offline
Scone
Senior Member
Join Date: Apr 2010
Location: England
Old 08-12-2010 , 07:10   Re: I'm having some problems. I need your help.
Reply With Quote #5

There's a serious security issue in that code - the client's name isn't being escaped. If they set their name to, for example:

Code:
';DROP TABLE verifysystem;SELECT '
Your query becomes this:

Code:
SELECT `password` FROM `verifysystem` WHERE `name` = '';DROP TABLE verifysystem;SELECT ''
You're giving every user complete access to your database. Also, it will fail for all non-malicious users who have quotes in their name. See SQL_EscapeString in the API docs for more info.
__________________
Scone is offline
Scone
Senior Member
Join Date: Apr 2010
Location: England
Old 08-12-2010 , 13:53   Re: I'm having some problems. I need your help.
Reply With Quote #6

Quote:
Originally Posted by jonnybbush View Post
you have to drop your table and create a new table with the select command
This man knows his stuff.
__________________
Scone is offline
duydangle
Senior Member
Join Date: May 2010
Old 08-13-2010 , 05:49   Re: I'm having some problems. I need your help.
Reply With Quote #7

I'm fixing security risk. Thank you.

If someone share his account, how can be he automatically kicked?

Quote:
Originally Posted by jonnybbush View Post
This is a security issue you have to drop your table and create a new table with the select command using this you have to easy find your query and solve faster so please change your older query with new query.
Can you explain more specifically?

Last edited by duydangle; 08-13-2010 at 05:52.
duydangle is offline
duydangle
Senior Member
Join Date: May 2010
Old 08-13-2010 , 12:44   Re: I'm having some problems. I need your help.
Reply With Quote #8

I think the security risk can be solved by not accepting special symbols when signing up.
duydangle is offline
daryematera
BANNED
Join Date: Nov 2010
Old 11-10-2010 , 13:03   Re: I'm having some problems. I need your help.
Reply With Quote #9

This is a security problem it is necessary to drop the table and create a new table, select the command that is easy for you to find the query, and to resolve more quickly and use some simple query you can easily find their information, and its high level of work in your experience.
daryematera is offline
FaTony
Veteran Member
Join Date: Aug 2008
Old 11-11-2010 , 00:05   Re: I'm having some problems. I need your help.
Reply With Quote #10

I wonder why not to use SteamID... Only non-steam pops up.
__________________
FaTony 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 19:08.


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