.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> ASP.NET Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Change the old password to new password in Asp.net

Posted By:satyapriyanayak       Posted Date: October 31, 2013    Points: 40    Category: ASP.NET Controls    URL: http://www.dotnetspark.com  

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



     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend