0

I'll use a select in asp.net page which i.e:

string name=TexBox1.Text;
string pas=TextBox2.Text;
string c="select * from users where name='"+name+"' and password ='"+pas+"'";

İs there any methods to preventing sql injections.

6
  • 7
    Use prepared statements. Commented Apr 24, 2013 at 12:33
  • can you give an examp. Commented Apr 24, 2013 at 12:35
  • 2
    Also, never store the password itself in the database. Always use a hash of the password with added salt, probably using Oracle's DBMS_CRYPTO PL/SQL package. See stackoverflow.com/questions/8339107/… Commented Apr 24, 2013 at 12:39
  • 1
    Microsoft article on prepared statements Commented Apr 24, 2013 at 12:40
  • Hash is always tasty, especially with a little salt :) Commented Apr 24, 2013 at 12:42

1 Answer 1

0

First, you must validate the input data in your code and then use it like parameters.. because if occurs an unhandled exception and you are returning sensitive data like "connection strings" you are giving usefull information like "Column" and "Table"names and that is dangerous. Second, add a "Data Access Layer" to handle your code not in "Code Behind". You can use "Store Procedures" and call them from your code, using this way you hide the query of the programming logic and only pass parameters to the store preocedure and he do the job and you only return the error in the case that a exception occurs.

This preventions are the basics in a small application but exists many others way to avoid SQL Injections.

Sign up to request clarification or add additional context in comments.

2 Comments

I'm working with important datas,so I will use hashing or other powerfull methods,thank for your idea,sorry I bought your time
Hashing is only for passwords if any error occurs you´re returning sensitive data like table and column names and that is SQL Injection. I recommend that you validate the input if you not have time to avoid sql injection, hope this help ;-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.