Using Public Partial Class New Protected Void Object: Home Sqlconnection Sqlconnection Eventargs
Using Public Partial Class New Protected Void Object: Home Sqlconnection Sqlconnection Eventargs
Page { SqlConnection con = new SqlConnection("Data Source=CMC101\\SQLEXPRESS;Initial Catalog=batch8;Integrated Security=true"); protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { string u1 = null, ps = null; try { con.Open(); SqlCommand cmd = new SqlCommand("select userid,password from std where userid='"+TextBox1.Text+"' and password='"+TextBox2.Text+"'", con); SqlDataReader sdr = cmd.ExecuteReader(); if (sdr.Read()) { u1 = sdr["userid"].ToString(); ps = sdr["password"].ToString(); } if (TextBox1.Text == u1 && TextBox2.Text == ps) { Session["user"] = TextBox1.Text; Response.Redirect("welcome.aspx?user-name:" + Session["user"].ToString()); } else { Label1.Text = "Wrong!! Userid or Password"; } con.Close(); } catch (Exception e1) { Label1.Text = e1.Message; }
} //forget password protected void LinkButton1_Click(object sender, EventArgs e) { string u1 = null; try { con.Open(); SqlCommand cmd = new SqlCommand("select userid from std where userid='" + TextBox1.Text + "'", con); SqlDataReader sdr = cmd.ExecuteReader(); if (sdr.Read()) { u1 = sdr["userid"].ToString(); } if (TextBox1.Text == u1) { Session["user"] = TextBox1.Text; Response.Redirect("forgetpassword.aspx?user-name:" + Session["user"].ToString()); } else { Label1.Text = "Wrong!! Userid"; } con.Close(); } catch (Exception e1) { Label1.Text = e1.Message; } } }
using System.Data.SqlClient; public partial class forgetpassword : System.Web.UI.Page { SqlConnection con = new SqlConnection("Data Source=CMC101\\SQLEXPRESS;Initial Catalog=batch8;Integrated Security=true"); protected void Page_Load(object sender, EventArgs e) { string sec = null; if (!IsPostBack) { if (Session["user"] != null) { try { con.Open(); SqlCommand cmd = new SqlCommand("select sec_que from std where userid='" + Session["user"].ToString() + "'", con); SqlDataReader sdr = cmd.ExecuteReader(); if (sdr.Read()) { sec = sdr["sec_que"].ToString(); } TextBox3.Text = sec.ToString(); con.Close(); } catch (Exception e1) { Label1.Text = e1.Message; }
} else { }
Response.Redirect("home.aspx");
} } protected void Button1_Click(object sender, EventArgs e) { string ps = null,ans=null; try { con.Open(); SqlCommand cmd = new SqlCommand("select password,sec_ans from std where userid='" + Session["user"].ToString() + "' and sec_ans='"+TextBox4.Text+"'", con);
SqlDataReader sdr = cmd.ExecuteReader(); if (sdr.Read()) { ps = sdr["password"].ToString(); ans = sdr["sec_ans"].ToString(); } if (TextBox4.Text == ans) { Label1.Text = "Dear user your password is::" + ps.ToString(); } else { Label1.Text = "Wrong answer"; } con.Close(); } catch (Exception e1) { Label1.Text = e1.Message; } } }
using System.Data.SqlClient; public partial class register : System.Web.UI.Page { SqlConnection con = new SqlConnection("Data Source=CMC101\\SQLEXPRESS;Initial Catalog=batch8;Integrated Security=true"); protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { try { con.Open();
SqlCommand cmd = new SqlCommand("insert into std values('"+TextBox1.Text+"','"+TextBox3.Text+"','"+DropDownList1.Selecte dValue+"','"+TextBox4.Text+"',"+TextBox5.Text+")",con); cmd.ExecuteNonQuery(); Session["user"]=TextBox1.Text; Response.Redirect("welcome.aspx?username:"+Session["user"].ToString()); con.Close(); } catch (Exception e1) { Label1.Text = e1.Message; } } }
using System.Data.SqlClient; public partial class welcome : System.Web.UI.Page { SqlConnection con = new SqlConnection("Data Source=CMC101\\SQLEXPRESS;Initial Catalog=batch8;Integrated Security=true"); protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (Session["user"] != null) { Label2.Text = "Welcome, " + Session["user"].ToString(); Response.ClearHeaders(); Response.AddHeader("Cache-Control", "no-cache, nostore, max-age=0, must-revalidate"); Response.AddHeader("Pragma", "no-cache"); }
else { } Response.Redirect("home.aspx"); } } protected void LinkButton1_Click(object sender, EventArgs e) { Session["user"] = null; Session.Abandon(); Session.Clear(); Response.Redirect("home.aspx"); } protected void Button1_Click(object sender, EventArgs e) { try { con.Open(); SqlCommand cmd = new SqlCommand("update std set password='"+TextBox3.Text+"' where userid='"+Session["user"].ToString() +"' and password='"+TextBox1.Text+"'", con); cmd.ExecuteNonQuery(); Label4.Text = "password changed.."; con.Close(); } catch (Exception e1) { Label4.Text = e1.Message; } } }