using System; using System.Collections.Generic; using System.Configuration; using System.Data.SqlClient; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace BCD.admin { public partial class passwordchange : System.Web.UI.Page { SqlConnection connect = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString); SqlCommand cmd; SqlDataAdapter adp; Class1 obj = new Class1(); protected void Page_Load(object sender, EventArgs e) { } byte changepass; protected void btnSave_Click(object sender, EventArgs e) { if (txtcurrentpwd.Text == "") { ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "err_msg", "alert('Please Enter Current Password');", true); } else if (txtpwd.Text == "") { ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "err_msg", "alert('Please Enter New Password');", true); } else if (txtconpwd.Text == "") { ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "err_msg", "alert('Please Enter New Confirm Password');", true); } else if (txtconpwd.Text != txtpwd.Text) { ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "err_msg", "alert('New Password and Confirm Password does not match');", true); } else { connect.Open(); string selpass = "select * from aadminlogin where username='" + Session["UserName"] + "'"; SqlCommand cmd = new SqlCommand(selpass, connect); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { if (txtcurrentpwd.Text == reader["pwd"].ToString()) { changepass = 1; } } reader.Close(); connect.Close(); if (changepass == 1) { connect.Open(); string update = "update aadminlogin set pwd=@pwd where username ='" + (string)Session["UserName"] + "'"; SqlCommand cmdupdate = new SqlCommand(update, connect); cmdupdate.Parameters.AddWithValue("@pwd", txtconpwd.Text); cmdupdate.ExecuteNonQuery(); connect.Close(); ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "err_msg", "alert('Password Change Successfully');", true); } else { ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "err_msg", "alert('Old Password does not match');", true); txtconpwd.Text = ""; txtcurrentpwd.Text = ""; txtpwd.Text = ""; } } } } }