In this blog we will know how to change the old password to
new password in asp.net.
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="Change_password_in_asp._Default" %>
<!DOCTYPE html
PUBLIC "-//W3C//DTD
XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form
id="form1"
runat="server">
<div>
<asp:Label ID="Label1" runat="server"
Text="Password:"
Width="150px"></asp:Label>
<asp:TextBox ID="txtpassword"
runat="server"></asp:TextBox>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator1"
runat="server"
ControlToValidate="txtpassword" ErrorMessage="RequiredFieldValidator">Password
cannot be blank</asp:RequiredFieldValidator>
<br />
<asp:Label ID="Label2" runat="server"
Text="New
Password:" Width="150px"></asp:Label>
<asp:TextBox ID="txtnpassword"
runat="server"></asp:TextBox>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator2"
runat="server"
ControlToValidate="txtnpassword" ErrorMessage="RequiredFieldValidator">NewPassword
cannot be blank</asp:RequiredFieldValidator>
<br />
<asp:Label ID="Label3" runat="server"
Text="Confirm New
Password:"
Width="150px"></asp:Label>
<asp:TextBox ID="txtcpassword"
runat="server"></asp:TextBox>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator3"
runat="server"
ControlToValidate="txtcpassword" ErrorMessage="RequiredFieldValidator">ConfirmPassword
cannot be blank</asp:RequiredFieldValidator>
<asp:CompareValidator
ID="CompareValidator1"
runat="server"
ControlToCompare="txtnpassword" ControlToValidate="txtcpassword"
ErrorMessage="CompareValidator">Not equal</asp:CompareValidator>
<br />
<asp:Button ID="btn_cpass"
runat="server"
Text="Change
password" />
<asp:Button ID="btn_clear"
runat="server"
Text="Clear"
/>
</div>
<asp:GridView ID="GridView1"
runat="server">
</asp:GridView>
</form>
</body>
</html>
Imports System.Data
Imports System.Data.SqlClient
Partial Public
Class _Default
Inherits System.Web.UI.Page
Dim strConnString As String =
System.Configuration.ConfigurationManager.ConnectionStrings.Item("ConnectionString").ToString()
Dim con As New
SqlConnection(strConnString)
Dim str As String
Dim com As SqlCommand
Dim sqlda As SqlDataAdapter
Dim ds As
DataSet
Dim up As
Byte
Protected Sub btn_cpass_Click(ByVal
sender As Object,
ByVal e As
EventArgs) Handles btn_cpass.Click
Try
If con.State =
ConnectionState.Open Then
con.Close()
End If
con.Open()
str = "select * from
emp"
com = New
SqlCommand(str, con)
Dim reader As SqlDataReader = com.ExecuteReader
Do While reader.Read
If txtpassword.Text
= reader("oldpwd") Then
up = 1
End If
Loop
reader.Close()
con.Close()
If up = 1 Then
con.Open()
str = "update emp
set oldpwd='" & txtcpassword.Text & "' where oldpwd='" & txtpassword.Text & "'"
com = New
SqlCommand(str, con)
com.ExecuteNonQuery()
con.Close()
Response.Write("Password
changed")
Else
Response.Write("Please
enter correct Oldpassword")
txtpassword.Focus()
End If
Catch ex As Exception
Response.Write(ex.Message)
End Try
clear()
bindgrid()
End Sub
Protected Sub btn_clear_Click(ByVal
sender As Object,
ByVal e As
EventArgs) Handles btn_clear.Click
clear()
End Sub
Sub clear()
txtpassword.Text = ""
txtnpassword.Text = ""
txtcpassword.Text = ""
txtpassword.Focus()
End Sub
Protected Sub Page_Load(ByVal
sender As Object,
ByVal e As
EventArgs) Handles Me.Load
If Not
IsPostBack Then
bindgrid()
End If
End Sub
Sub bindgrid()
con.Open()
str = "select * from
emp"
com = New SqlCommand(str,
con)
sqlda = New
SqlDataAdapter(com)
ds = New DataSet()
sqlda.Fill(ds, "emp")
GridView1.DataSource = ds
GridView1.DataMember = "emp"
GridView1.DataBind()
con.Close()
End Sub
End
Class
Thanks for reading