2 Replies - 2623 Views - Last Post: 07 December 2012 - 02:42 PM Rate Topic: -----

#1 Sand-Man  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 13-November 12

Visual Basic 2008 password verification

Posted 07 December 2012 - 02:17 PM

hi guys, everything works fine but when i try to log in with a correct username but incorrect password nothing happen. can somebody help me fix this.
much appreciated




 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Login.Click

        If txtUsername.Text = "" Then
            MsgBox("Error, You Need Atleast One Letter", MsgBoxStyle.Critical)
        Else
            If My.Computer.FileSystem.DirectoryExists(" C:\Users\Omer Muhaidi\Downloads\Visual Basic Work\Omer Project" + txtUsername.Text + "\") Then
                Dim USERREAD As System.IO.StreamReader = New System.IO.StreamReader("C:\Users\Omer Muhaidi\Downloads\Visual Basic Work\Omer Project" + txtUsername.Text + "\" + "USERNAME.TXT")
                Dim userline As String
                Dim PASSREAD As System.IO.StreamReader = New System.IO.StreamReader("C:\Users\Omer Muhaidi\Downloads\Visual Basic Work\Omer Project" + txtUsername.Text + "\" + "PASSWORD.TXT")
                Dim PASSLINE As String
                Do
                    PASSLINE = txtPassword.Text
                    userline = USERREAD.ReadLine
                    Console.WriteLine(PASSLINE)
                    Console.WriteLine(userline)
                Loop Until userline Is Nothing
                If txtPassword.Text = "" Then
                    MsgBox("Error, Please Input A Password", MsgBoxStyle.Critical)
                Else
                    If PASSLINE = PASSREAD.ReadLine() = True Then
                        MsgBox("Login Successful, You Are Now Logged In " + txtUsername.Text)
                        TopicForm.Show()
                    End If

                End If

            Else

                MsgBox("That Username Doesnt Exist", MsgBoxStyle.Critical)


            End If

        End If


    End Sub



Is This A Good Question/Topic? 0
  • +

Replies To: Visual Basic 2008 password verification

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5535
  • View blog
  • Posts: 11,861
  • Joined: 02-June 10

Re: Visual Basic 2008 password verification

Posted 07 December 2012 - 02:26 PM

Don't do this:
If My.Computer.FileSystem.DirectoryExists(" C:\Users\Omer Muhaidi\Downloads\Visual Basic Work\Omer Project" + txtUsername.Text + "\") Then


  • You should use the SpecialFolders enum to get the user's directory.
  • You should use a property to hold the UserName and not use a GUI control like it were a variable(txtUsername.Text).
  • You should use System.IO.Path.Combine to build up a path hierarchy and not hard code this stuff. So much can go wrong with doing it the way you have. And it won't work on any user or PC but yours.


As for finding the issue, that's basic debugging.

Looking at your code sample you're what, maybe 2 weeks into a class. You aren't ready to be building an application from scratch. You don't know how much you don't know. You can't design until you have a better command of the coding language. For now, just follow the Learning Series tutorials and pickup a couple "Learn C# in 30 days" type books to do in addition to your course work.


rookie: What this shows us is that you aren't familiar with breakpoints and how to debug your own code.


tlhIn`toq's FAQ list

Learning to debug one's own code is an essential skill. Sadly, one that apparently few college courses teach. Silly if you ask me.

Placing breakpoints and walking through the code line by line allows you to actually WATCH it execute.

Visualizing what your code does will let you see why it behaves the way it does.

It would be well worth your time to do the tutorials on FAQ 2. A couple hours learning this skill will save you hundreds of hours of confusion in one project alone.


TOP most asked:
What does this error message mean?
FAQ 2: How do I debug
FAQ 3: How do I make Class1/Form1 talk to Class2/Form2


FAQ (Frequently Asked Questions - Updated DEC 2012
Spoiler



This post has been edited by tlhIn`toq: 07 December 2012 - 02:27 PM

Was This Post Helpful? 1
  • +
  • -

#3 Sand-Man  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 13-November 12

Re: Visual Basic 2008 password verification

Posted 07 December 2012 - 02:42 PM

cheers pal
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1