usingSystem;usingSystem.Data;usingSystem.Configuration;usingSystem.Collections;usingsystem.web;usingSystem.Web.Security;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingSystem.Web.UI.WebControls.WebParts;usingSystem.Web.UI.HtmlControls;usingSystem.Data.SqlClient; Public Partial classchangepassword:system.web.ui.page{protected voidPage_Load (Objectsender, EventArgs e) { } protected voidButton1_Click (Objectsender, EventArgs e) { //read the Web. config profile database connection string stringstrconstring = configurationmanager.connectionstrings["ConnectionString"]. ConnectionString; //To create a SQL database connection objectSqlConnection conn =NewSqlConnection (); Conn. ConnectionString=strconstring; Conn. Open (); Try{SqlCommand Selectedcmd=NewSqlCommand ("Select from users where Userid= '"+session["userid"]. ToString () +"' and password= '"+origin. Text.trim () +"'", conn); SqlDataReader SDR=Selectedcmd. ExecuteReader (); if(SDR). Read ()) {SqlCommand Updatecmd=NewSqlCommand ("Update users set password= '"+ newpwd. Text.trim () +"' where userid= '"+ session["userid"]. ToString () +"'", conn); inti =Updatecmd. ExecuteNonQuery (); if(i = =1) {Response.Write ("<script language =javascript>alert (' Password modified successfully ') </script>"); } Else{Response.Write ("<script language =javascript>alert (' Password modification failed ') </script>"); } } Else{Response.Write ("<script Language =javascript>alert (' original password error ') </script>"); } } Catch(System.Exception ee) {Response.Write ("<script language =javascript>alert ('"+ EE. Message.tostring () +"') </script>"); } finally{Conn. Close (); } }
ASP. Net Change Password code