Imports System.Data.SqlClient
Public Class frm_forgetpw
    Dim cmd As SqlCommand = Nothing
    Dim conn As New SqlConnection(System.Configuration.ConfigurationSettings.AppSettings("SO_Conn"))
    Private Sub frm_forgetpw_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub btn_chpw_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_chpw.Click
        If Me.txt_expw.Text.Trim = "" Then
            MsgBox("Add existing Password!", MsgBoxStyle.Information, "Change Password")
            txt_expw.Focus()
        ElseIf Me.txt_newpw.Text.Trim = "" Then
            MsgBox("Add new Password!", MsgBoxStyle.Information, "Change Password")
            txt_newpw.Focus()
        ElseIf Me.txt_renewpw.Text.Trim = "" Then
            MsgBox("Add New Password again!", MsgBoxStyle.Information, "Change Password")
            txt_renewpw.Focus()
        ElseIf Me.txt_renewpw.Text.Trim <> Me.txt_newpw.Text.Trim Then
            MsgBox("New Password and re-password mismatch, add again!", MsgBoxStyle.Information, "Change Password")
            txt_newpw.Focus()

        Else
            If conn.State <> ConnectionState.Open Then
                conn.Open()
            End If
            Dim dr As SqlDataReader = Nothing
            Dim cmdtext As String = "SO_SelectUserFPW"
            cmd = Nothing
            'cmd = New SqlCommand("select * from tbl_users  where id = " & commonUser.Common.uID & " and password = '" & Me.txt_expw.Text.Trim & "'", conn)
            cmd = New SqlCommand(cmdtext, conn)
            cmd.CommandType = CommandType.StoredProcedure
            cmd.Parameters.AddWithValue("@Uid", commonUser.Common.uID)
            cmd.Parameters.AddWithValue("@Pwd", Me.txt_expw.Text.Trim)
            dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
            If (dr.Read) Then
                dr.Close()
                If conn.State <> ConnectionState.Open Then
                    conn.Open()
                End If
                Try
                    Dim cmdtext1 As String = "SO_UpdatePWD"
                    Dim cmd1 As New SqlCommand(cmdtext1, conn)
                    cmd1.CommandType = CommandType.StoredProcedure
                    cmd1.Parameters.AddWithValue("@Uid", commonUser.Common.uID)
                    cmd1.Parameters.AddWithValue("@Pwd", Me.txt_newpw.Text.Trim)
                    'Dim cmd1 As New SqlCommand("update tbl_users set password = '" & Me.txt_newpw.Text.Trim & "' where id = " & commonUser.Common.uID & "", conn)
                    cmd1.ExecuteNonQuery()
                    MsgBox("Password changed Successfully!!", MsgBoxStyle.Information, "Change Password")
                    Me.txt_newpw.Text = ""
                    Me.txt_renewpw.Text = ""
                    Me.txt_expw.Text = ""
                    Me.txt_expw.Focus()
                Catch ex As Exception
                End Try
            Else
                MsgBox("Add correct existing Password!", MsgBoxStyle.Information, "Change Password")
                txt_expw.Focus()
            End If

            If conn.State <> ConnectionState.Closed Then
                conn.Close()
            End If
        End If
    End Sub
End Class