Click here to Skip to main content
15,897,273 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: Disable Browser back button in FireFox Pin
dhulipudi20-Jun-07 2:18
dhulipudi20-Jun-07 2:18 
Questionperiodic update of gridview Pin
shafyq19-Jun-07 21:39
shafyq19-Jun-07 21:39 
AnswerRe: periodic update of gridview Pin
shafyq19-Jun-07 21:55
shafyq19-Jun-07 21:55 
Questionasp.net, access database Pin
ling_luv19-Jun-07 21:36
ling_luv19-Jun-07 21:36 
AnswerRe: asp.net, access database Pin
Chetan Ranpariya19-Jun-07 21:50
Chetan Ranpariya19-Jun-07 21:50 
GeneralRe: asp.net, access database Pin
ling_luv19-Jun-07 21:59
ling_luv19-Jun-07 21:59 
QuestionPropagating .NET remoting exception back to the remoting client Pin
Talal Sultan19-Jun-07 21:30
Talal Sultan19-Jun-07 21:30 
QuestionPreventing SQL Injection [modified] Pin
ASPnoob19-Jun-07 20:56
ASPnoob19-Jun-07 20:56 
Hi, I'm atempting to prevent SQL injection by incorporating the function below into my code, but I'm not sure how to change my select statement to make it work. Below is the function I'm intending to use and below it is my code.
function killChars(strWords)
dim badChars
dim newChars

badChars = array("select", "drop", ";", "--", "insert", "delete", "xp_")
newChars = strWords

for i = 0 to uBound(badChars)
newChars = replace(newChars, badChars(i), "")
next

killChars = newChars

end function 

Private Sub lblRegister_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblRegister.Click
       Dim myConnection As OdbcConnection
       Dim myCommand As OdbcCommand
       Dim strInsert As String
       Dim strSQL As String
       strSQL = String.Empty

        myConnection = New OdbcConnection("Driver={MySQL ODBC 3.51 Driver};Server=myServer;Database=myDB;User=myUser; Password=myPW;Option=3;")
           strSQL = String.Format("SELECT UserName FROM myTable WHERE (UserName='{0}');", txtUserName.Text)
           myCommand = New OdbcCommand(strSQL, myConnection)
           myCommand.CommandType = CommandType.Text
           myConnection.Open()

           Dim result As Integer = CType(myCommand.ExecuteScalar,Integer)
           ' If record count > 0, then UserName already exists in the database
           If result > 0 Then
              lblMessage.Text = "User name already exists in the database"
          Else
              strInsert = "INSERT into myTable (Password,UserName)values (?,?)"
              Dim myCommand1 As OdbcCommand = New OdbcCommand(strInsert, myConnection)
              myCommand1.Parameters.Add(new OdbcParameter("@Password", txtPassword.Text))
              myCommand1.Parameters.Add(new OdbcParameter("@UserName", txtUserName.Text))

              Dim result1 As Integer = myCommand1.ExecuteNonQuery()
          End If
              'close the connection
              myConnection.Close()
End Sub

I don't know how to modify the lines

strSQL = String.Format("SELECT UserName FROM myTable WHERE (UserName='{0}');", txtUserName.Text)


and

strInsert = "INSERT into myTable (Password,UserName)values (?,?)"


to make the KillChars function work. Any suggestions will be grately appreciated, thank you in advance for your help.





-- modified at 3:07 Wednesday 20th June, 2007
AnswerRe: Preventing SQL Injection Pin
Arun.Immanuel19-Jun-07 21:08
Arun.Immanuel19-Jun-07 21:08 
AnswerRe: Preventing SQL Injection Pin
badgrs19-Jun-07 23:33
badgrs19-Jun-07 23:33 
AnswerThis I too agree badgrs - chk it out here Pin
Sylvester george20-Jun-07 0:06
Sylvester george20-Jun-07 0:06 
Questionquery string Pin
saravanan0519-Jun-07 20:46
saravanan0519-Jun-07 20:46 
AnswerRe: query string Pin
Sylvester george19-Jun-07 21:12
Sylvester george19-Jun-07 21:12 
AnswerRe: query string Pin
Sathesh Sakthivel19-Jun-07 21:13
Sathesh Sakthivel19-Jun-07 21:13 
GeneralRe: query string Pin
Sandeep Akhare19-Jun-07 21:19
Sandeep Akhare19-Jun-07 21:19 
GeneralRe: query string Pin
Sathesh Sakthivel19-Jun-07 21:25
Sathesh Sakthivel19-Jun-07 21:25 
GeneralRe: query string Pin
Sandeep Akhare19-Jun-07 21:33
Sandeep Akhare19-Jun-07 21:33 
AnswerRe: query string Pin
Arun.Immanuel19-Jun-07 21:14
Arun.Immanuel19-Jun-07 21:14 
AnswerRe: query string Pin
Sandeep Akhare19-Jun-07 21:17
Sandeep Akhare19-Jun-07 21:17 
QuestionRe: query string Pin
saravanan0519-Jun-07 22:54
saravanan0519-Jun-07 22:54 
QuestionRe: query string Pin
Sandeep Akhare19-Jun-07 23:23
Sandeep Akhare19-Jun-07 23:23 
QuestionRe: query string Pin
saravanan0520-Jun-07 0:00
saravanan0520-Jun-07 0:00 
AnswerRe: query string Pin
Sandeep Akhare20-Jun-07 0:16
Sandeep Akhare20-Jun-07 0:16 
QuestionWho to Rewrite URL? Pin
chand1019-Jun-07 20:46
chand1019-Jun-07 20:46 
AnswerRe: Who to Rewrite URL? Pin
N a v a n e e t h19-Jun-07 21:03
N a v a n e e t h19-Jun-07 21:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.