Public Class frmChangePassword
    Private Sub btnClose_Click(sender As Object, e As EventArgs) Handles btnClose.Click
        Me.Close()
    End Sub

    Private Sub frmChangePassword_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        txtCurrentPassword.Select()
    End Sub

    Private Sub btnSubmit_Click(sender As Object, e As EventArgs) Handles btnSubmit.Click
        If txtCurrentPassword.Text = "" Then
            ErrorProvider1.SetError(txtCurrentPassword, "Mandatory field.")
        ElseIf txtNewPassword.Text = "" Then
            ErrorProvider1.SetError(txtNewPassword, "Mandatory field.")
        ElseIf txtRePassword.Text = "" Then
            ErrorProvider1.SetError(txtRePassword, "Mandatory field.")
        ElseIf Not (txtNewPassword.Text = txtRePassword.Text) Then
            MsgBox("New password and re-password does not match.", MsgBoxStyle.Critical, "Critical")
        Else
            ExecuteSQLQuery("SELECT  *  FROM   ApplicationUser  WHERE    (USER_ID = " & xUser_ID & ") AND (Password = '" & str_repl(txtCurrentPassword.Text) & "')")
            If sqlDT.Rows.Count > 0 Then
                If MsgBox("Would you like to change this password?", MsgBoxStyle.YesNo + MsgBoxStyle.Exclamation, "Confirm..") = MsgBoxResult.Yes Then
                    ExecuteSQLQuery(" UPDATE  ApplicationUser SET Password = '" & str_repl(txtRePassword.Text) & "' WHERE  USER_ID = " & xUser_ID & "")
                    MsgBox("Password successfully changed.", MsgBoxStyle.Information, "Information")
                    Me.Close()
                End If
            Else
                MsgBox("Sorry! Current password does not match.", MsgBoxStyle.Critical, "Critical")
            End If
        End If
    End Sub
End Class