1
using System;2
using System.Collections;3
using System.ComponentModel;4
using System.Data;5
using System.Drawing;6
using System.Web;7
using System.Web.SessionState;8
using System.Web.UI;9
using System.Web.UI.WebControls;10
using System.Web.UI.HtmlControls;11
using System.Data.SqlClient;12
namespace Ado.net13


{14

/**//// <summary>15
/// WebForm1 的摘要说明。16
/// </summary>17
public class WebForm1 : System.Web.UI.Page18

{19
protected System.Web.UI.WebControls.TextBox TextBox1;20
protected System.Web.UI.WebControls.TextBox TextBox2;21
protected System.Web.UI.WebControls.Button Button1;22
protected System.Web.UI.WebControls.Button Button2;23
24
private void Page_Load(object sender, System.EventArgs e)25

{26
// 在此处放置用户代码以初始化页面27
}28

29

Web 窗体设计器生成的代码#region Web 窗体设计器生成的代码30
override protected void OnInit(EventArgs e)31

{32
//33
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。34
//35
InitializeComponent();36
base.OnInit(e);37
}38
39

/**//// <summary>40
/// 设计器支持所需的方法 - 不要使用代码编辑器修改41
/// 此方法的内容。42
/// </summary>43
private void InitializeComponent()44

{ 45
this.Button1.Click += new System.EventHandler(this.Button1_Click);46
this.Button2.Click += new System.EventHandler(this.Button2_Click);47
this.Load += new System.EventHandler(this.Page_Load);48

49
}50
#endregion51

52
private SqlConnection con()53

{//下面有调用几次这个,所以就做个方法,呵呵,没有意见吧54
SqlConnection con=new SqlConnection("server=.;database=voteone;uid=sa;pwd=980123;");55
return con;56
}57
private void Button1_Click(object sender, System.EventArgs e)58

{59
SqlConnection con=this.con();60
con.Open();61
SqlCommand cmd=new SqlCommand("select * from admin where name='"+TextBox1.Text+"' and pwd='"+TextBox2.Text+"'",con);62
SqlDataReader sdr=cmd.ExecuteReader();63
if(sdr.Read())64

{//这个成功不需要输入密码或者连用户名都不用输入就可以得到65
//例如你在第第一个文本框里输入 thc '-- (这个是假设我们知道用户名是thc)或者 ' or 1=1-- (这个更厉害了,更本就不需要知道什么,重要知道 1=1就可以了)66
Response.Write("登陆成功");67
}68
else69

{70
Response.Write("失败");71
}72
}73

74
private void Button2_Click(object sender, System.EventArgs e)75

{//下面方法主要是使用了Replace关键字把传近来的字符中的 单引号给替换了('),其他没有什么,呵呵76
SqlConnection con=this.con();77
con.Open();78
SqlCommand cmd=new SqlCommand("select * from admin where name='"+TextBox1.Text.Replace("'","''")+"' and pwd='"+TextBox2.Text.Replace("'","''")+"'",con);79
SqlDataReader sdr=cmd.ExecuteReader();80
if(sdr.Read())81

{82
Response.Write("登陆成功");83
}84
else85

{86
Response.Write("失败");87
}88
}89
}90
}91

1

<%
@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="Ado.net.WebForm1" %>2
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >3
<HTML>4
<HEAD>5
<title>WebForm1</title>6
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">7
<meta name="CODE_LANGUAGE" Content="C#">8
<meta name="vs_defaultClientScript" content="JavaScript">9
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">10
</HEAD>11
<body MS_POSITIONING="GridLayout">12
<form id="Form1" method="post" runat="server">13
<asp:TextBox id="TextBox1" style="Z-INDEX: 101; LEFT: 32px; POSITION: absolute; TOP: 80px" runat="server"></asp:TextBox>14
<asp:TextBox id="TextBox2" style="Z-INDEX: 102; LEFT: 32px; POSITION: absolute; TOP: 120px" runat="server"></asp:TextBox>15
<asp:Button id="Button1" style="Z-INDEX: 103; LEFT: 32px; POSITION: absolute; TOP: 160px" runat="server"16
Text="有漏洞"></asp:Button>17
<asp:Button id="Button2" style="Z-INDEX: 104; LEFT: 120px; POSITION: absolute; TOP: 160px" runat="server"18
Text="修改后"></asp:Button>19
</form>20
</body>21
</HTML>22
