forked from CxCE/Exercises
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsqli.aspx.cs
More file actions
70 lines (58 loc) · 1.98 KB
/
sqli.aspx.cs
File metadata and controls
70 lines (58 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System;
using System.Data;
using System.Data.SqlClient;
namespace CxCE_Demo
{
public partial class sqli : System.Web.UI.Page
{
static string username = String.Empty;
static int age = -1;
protected void Page_Load(object sender, EventArgs e)
{
try
{
string ID = Request.QueryString[0];
getName(ID);
}
catch { }
}
private void getName(string ID)
{
string username = "No name";
SqlConnection conn = new SqlConnection("Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=" + Constants.DB_PASSWORD + ";");
SqlCommand cmd = new SqlCommand();
SqlDataReader reader;
cmd.CommandText = "SELECT NAME FROM Users WHERE ID = " + ID;
cmd.CommandType = CommandType.Text;
cmd.Connection = conn;
conn.Open();
reader = cmd.ExecuteReader();
if (reader.HasRows)
{
username = reader["NAME"].ToString();
age = getAge(username);
}
message.Text = "Welcome " + username;
conn.Close();
}
private int getAge(string name)
{
SqlConnection conn = new SqlConnection("Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=" + Constants.DB_PASSWORD + ";");
SqlCommand cmd = new SqlCommand();
SqlDataReader reader;
cmd.CommandText = "SELECT AGE FROM Users WHERE NAME = '" + name + "'";
cmd.CommandType = CommandType.Text;
cmd.Connection = conn;
conn.Open();
reader = cmd.ExecuteReader();
if (reader.HasRows)
return(reader.GetInt32(0));
conn.Close();
return -1;
}
protected void submit_Click(object sender, EventArgs e)
{
getName(name.Text);
}
}
}