Help retrieve the user password

helio_matcha

New member
Joined
Sep 28, 2007
Messages
4
Programming Experience
Beginner
Hi, i have a VB form(retrieve password) that is suppose to retrieve the user password from the database if he has forgotten it.

But upon registration i asked him in another form to fill his id, secretQuestion and answer and this information his successfully send to the database.

However if he wants to retrieve the password he needs to key in his id, secretquestion and answer, if they match against the database then i make a select statement using the id to retrieve his password.

But in my code there is an error, i have but i don't find the error, can somebody help me?

My code is here, it's really simple to understand:

VB.NET:
'provides classes that are required to connect to OLE DB data sources
Imports System.Data.OleDb
Public Class ForgetPwd
    Inherits System.Windows.Forms.Form
    'The System.Data.OleDb.OleDbConnection class represents a connection to OleDb data source
    Dim dr, dr1 As OleDbDataReader
    'The System.Data.OleDb.OleDbConnection class represents a connection to OleDb data source
    Dim cn As OleDbConnection
    'The System.Data.OleDb.OleDbCommand class represents a SQL statement or stored procedure 
    'that is executed in a database by an OLE DB provider. 
    Dim cmd, cmd1 As OleDbCommand
    Dim id, icount, bankAcc As Integer
    Dim answer, sQuestion, pass As String

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        id = txtID.Text
        answer = txtAnswer.Text
        sQuestion = cmbSecret.SelectedItem

        Try
            cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=D:\2007_Final Sem\BSD\projectRegistration.mdb;")
            cn.Open()
            cmd = New OleDbCommand("select * from registration WHERE id = '" & id & "' AND secretQuestion = '" & sQuestion & "' AND answer = '" & answer & "'", cn)
            cmd1 = New OleDbCommand("select * from registration WHERE id = '" & id & "' AND pass = '" & pass & "'", cn)

            dr = cmd.ExecuteReader
            dr1 = cmd1.ExecuteReader

            If dr.Read() Then
                cmd1 = New OleDbCommand("select * from registration WHERE id = '" & id & "' AND pass = '" & pass & "'", cn)
                dr1 = cmd1.ExecuteReader
                If dr1.Read() Then
                    MessageBox.Show("Your password is" & pass)
                Else
                    MessageBox.Show("Sorry make sure you have inserted the right information")
                End If
            End If
            cn.Close()

        Catch this As NullReferenceException
            this.GetBaseException()
            MessageBox.Show("Exception thrown")
        End Try
    End Sub
End Class

But instead it goes straight to my error message condition:
MessageBox.Show("Sorry make sure you have inserted the right information")
 
Back
Top