Tuesday, 28 January 2014

Change password code in asp.net using c#



 SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["CONNECTION"].ConnectionString);
 
        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            try
            {

                if (con.State == ConnectionState.Open)
                {
                    con.Close();
                }
                con.Open();
                SqlCommand cmd1 = new SqlCommand("select Upassword from UserRegistration where UEmail ='" + txtsid.Text + "' ", con);
                cmd1.CommandType = CommandType.Text;

                SqlDataAdapter da = new SqlDataAdapter(cmd1);
                DataSet ds = new DataSet();
                da.Fill(ds);
                if (txtPassword.Text != ds.Tables[0].Rows[0][0].ToString())
                {
                    lblMsg.Text = "Your password Is Wrong";
                    txtPassword.Focus();

                }
                else
                {


                    if (con.State == ConnectionState.Open)
                    {
                        con.Close();
                    }
                    con.Open();
                    SqlCommand cmd = new SqlCommand("Update UserRegistration set Upassword='" + txtNewPassword.Text + "' where UEmail='" + txtsid.Text + "' ", con);
                    cmd.CommandType = CommandType.Text;

                    cmd.ExecuteNonQuery();
                    con.Close();

                    lblMsg.Text = "Your Password Changed Succesfully...!";
                }
            }
            catch (Exception)
            {

                throw;
            }
        }
    }

No comments:

Post a Comment