我的代码有什么问题 [英] What's wrong in my code

查看:98
本文介绍了我的代码有什么问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  Dim  strid  As  整数 
Dim conn 作为 OleDbConnection( Provider = Microsoft.Jet.OLEDB.4.0;数据源= C:\\ \\ Users\Dew\Documents\Shubham \ShubhamProj \StudLib.mdb
conn.Open()
Dim cmd 作为 OleDbCommand
cmd = conn.CreateCommand()
strid = CInt (User2nd.Text)
cmd.CommandText = SELECT * FROM std_log where first_name ='& User1st.Text& 'and password ='& Password.Text& '和id ='& strid& ';
Dim dr As OleDbDataReader
dr = cmd.ExecuteReader()

解决方案

错字:

 id =& strid&;



但是,您应该使用参数查询在ASP中.NET-with-MS-Access [ ^ ]以防止sql注入。


正如Peter在解决方案1中指出的那样,这是错误的方法,因为你离开你的应用程序众所周知的漏洞被称为 SQL injecton 。这就是:

http:// xkcd.com/327 [ ^ ]。



这是你需要使用的: http://msdn.microsoft.com/en-us/library/ff648339.aspx [ ^ ]。



参见: http://en.wikipedia.org/wiki/SQL_injection [ ^ ]。



请看我过去的答案:

在com.ExecuteNonQuery()中更新EROR; [ ^ ],

你的名字没有显示名称吗? [ ^ ]。



-SA


使用sql参数尝试下面的代码,

 cmd.CommandText =   SELECT * FROM std_log where first_name =?和密码=?和id =?; 
cmd.Parameters.AddWithValue( first_name,User1st.Text)
cmd.Parameters.AddWithValue( password,密码。文本)
cmd.Parameters.AddWithValue( id,strid)
Dim dr As OleDbDataReader
dr = cmd.ExecuteReader()


Dim strid As Integer
Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data source=C:\Users\Dew\Documents\Shubham\ShubhamProj\StudLib.mdb")
conn.Open()
Dim cmd As OleDbCommand
cmd = conn.CreateCommand()
strid = CInt(User2nd.Text)
cmd.CommandText = "SELECT * FROM std_log where first_name='" & User1st.Text & "' and password='" & Password.Text & "' and id=' "& strid &" ';"
Dim dr As OleDbDataReader
dr = cmd.ExecuteReader()

解决方案

Typo:

id=" & strid & ";"


However, you should use Parameter-Queries-in-ASP.NET-with-MS-Access[^] to prevent sql injection.


As Peter pointed out in Solution 1, this is wrong approach, because you leave your application wide open to the well know exploit called SQL injecton. This is how:
http://xkcd.com/327[^].

This is what you need to use: http://msdn.microsoft.com/en-us/library/ff648339.aspx[^].

See also: http://en.wikipedia.org/wiki/SQL_injection[^].

And please see my past answers:
EROR IN UPATE in com.ExecuteNonQuery();[^],
hi name is not displaying in name?[^].

—SA


try below code with sql parameters,

cmd.CommandText = "SELECT * FROM std_log where first_name=? and password=? and id=?";
cmd.Parameters.AddWithValue("first_name", User1st.Text)
cmd.Parameters.AddWithValue("password", Password.Text)
cmd.Parameters.AddWithValue("id", strid)
Dim dr As OleDbDataReader
dr = cmd.ExecuteReader()


这篇关于我的代码有什么问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆