0% found this document useful (0 votes)
105 views6 pages

Using Public Partial Class New Protected Void Object: Home Sqlconnection Sqlconnection Eventargs

This document contains code for an ASP.NET web application that allows users to register, log in, log out, and change their password. It uses SQL Server to store user data in a database table. The code handles user registration by inserting new user data into the table. It also includes logic for logging users in by comparing their input credentials to those stored in the table, redirecting to different pages based on login status, and updating passwords in the table.

Uploaded by

Julie Sachan
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
105 views6 pages

Using Public Partial Class New Protected Void Object: Home Sqlconnection Sqlconnection Eventargs

This document contains code for an ASP.NET web application that allows users to register, log in, log out, and change their password. It uses SQL Server to store user data in a database table. The code handles user registration by inserting new user data into the table. It also includes logic for logging users in by comparing their input credentials to those stored in the table, redirecting to different pages based on login status, and updating passwords in the table.

Uploaded by

Julie Sachan
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 6

using System.Data.SqlClient; public partial class home : 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) { 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; } } }

You might also like