ARTICLE

Change password in VB.NET

Posted by Satyapriya Nayak Articles | Windows Forms VB.NET August 04, 2011
Here, we will see how to change password in VB.NET.
Download Files:
 
Reader Level:

We need to change your password frequently from time to time from being hacked. While changing we have to enter old password and your desired new password and to confirm it we have to again enter the new password.

Program

Imports System.Data

Imports System.Data.OleDb

Public Class Form1

    Dim ConnectionString As String = System.Configuration.ConfigurationSettings.AppSettings("dsn")

    Dim con As OleDbConnection

    Dim com As OleDbCommand

    Dim oledbda As OleDbDataAdapter

    Dim ds As DataSet

    Dim str As String

    Dim up As Byte

    Private Sub btn_change_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_change.Click

        If TextBox3.Text <> TextBox2.Text Then

 

            MsgBox("confirm password not matching with new passsword")

 

            TextBox3.Focus()

 

            Exit Sub

 

        End If

 

        Try

            'If con.State = ConnectionState.Open Then

            '    con.Close()

            'End If

            con = New OleDbConnection(ConnectionString)

            con.Open()

 

            str = "select * from login"

            com = New OleDbCommand(str, con)

            Dim reader As OleDbDataReader = com.ExecuteReader

 

            Do While reader.Read

 

                If TextBox1.Text = reader("oldpwd") Then

                    up = 1

                End If

            Loop

 

            If up = 1 Then

 

                str = "update login set newpwd='" & TextBox3.Text & "' where oldpwd='" & TextBox1.Text & "'"

                com = New OleDbCommand(str, con)

                com.ExecuteNonQuery()

                MsgBox("Password changed")

 

            Else

 

                MsgBox("Please enter correct Oldpassword and Newpassword")

                TextBox1.Focus()

 

            End If

            reader.Close()

            con.Close()

 

        Catch ex As Exception

 

            MsgBox(ex.Message)

 

        End Try

        clear()

        bind()

 

    End Sub

 

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        clear()

 

    End Sub

    Sub clear()

        If Len(TextBox1.Text) = 0 & Len(TextBox2.Text) = 0 Then

 

            TextBox1.Text = ""

            TextBox2.Text = ""

            TextBox3.Text = ""

 

 

        Else

            TextBox3.Text = ""

            TextBox1.Clear()

            TextBox2.Clear()

            TextBox3.Clear()

            TextBox1.Focus()

            'Me.Close()

 

        End If

    End Sub

 

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        bind()

    End Sub

    Sub bind()

        con = New OleDbConnection(ConnectionString)

        con.Open()

        str = "select * from login"

        com = New OleDbCommand(Str, con)

        oledbda = New OleDbDataAdapter(com)

        ds = New DataSet()

        oledbda.Fill(ds, "login")

        DataGridView1.DataSource = ds

        DataGridView1.DataMember = "login"

        con.Close()

    End Sub   

End Class

Output


changepassword.gif

Login to add your contents and source code to this article
share this article :
post comment
 
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor