k guys i have a text file that has a record of passwords, i am trying to read from that file if the guys username and passwords match access granted if not there denied.

read = System.IO.File.OpenText("password records.txt")
        username = txtUsername.Text

        For a = 1 To 10
            txtOutput.Text = read.Readline()
            If InStr(txtOutput.Text, username) Then
                count = txtOutput.Text.Length.ToString - 8
                password = Mid(txtOutput.Text, count, 9)
            End If
        Next a
        read.Close()

        correctPass = txtPassword.Text
        If correctPass = password Then
            MsgBox("You Have Gained Access!")
        Else

            MsgBox("Access Denied! Try Again!" & vbCrLf _
            & "If not registered please Press ""Click here to REGISTER""")
        End If

this is my code, but whenever i try it the password doesn't return anything.

Can you give us more information? Is InStr(txtOutput.Text, username) ever true? What does txtOuput.text look like within the first If block? What does count equal within the If block? I just want to know what things look line when the password = Mid(txtOutput.Text, count, 9) line is executed.

well, instr should be true, because if not then the person isn't registered in the password records.txt, the txtoutput is just a textbox that is hidden from the users view, i just did it to replace a string variable, thats all it is there for.

so just to sum it up, the user enter their username which is then stored in username variable, then the person username is searched for in password records.txt, if it is found which it should be the programs looks beside that username for the password since there on the same line and then compares that password to the password the user entered.

btw this is the new code:

Dim read As System.IO.StreamReader
        Dim username As String
        Dim password As String
        Dim count As Integer
        Dim correctPass As String
        Dim lines As String = 0
        public storage1 as string

        private sub btnEnter_click(ByVal sender As System.Object, ByVal e As System.EventArgs) handles btnEnter.click
        read = System.IO.File.OpenText("password records.txt")
        username = txtUsername.Text
         While Not read.ReadLine = Nothing
            lines = lines + 1
        End While
        For a = 1 To lines
            storage1 = read.Readline()
            If InStr(storage1, username) Then
                count = storage1.Text.Length.ToString - 8
                password = Mid(storage, count, 9)
            End If
        Next a
        read.Close()
         correctPass = txtPassword.Text
        If correctPass = password Then
            MsgBox("You Have Gained Access!")
        Else
             MsgBox("Access Denied! Try Again!" & vbCrLf _
            & "If not registered please Press ""Click here to REGISTER""")
        End If
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.