I have a text file that contains three lines.
1. Username
2. Password
3. Time Stamp
When creating a password it takes the username and makes the username the name of the file. Example: username: "Andrew" file: "Andrew.txt".
When I try to read the file it works great. When I put in the wrong password of the right file name it gives a custom message box. When I put in a username that has not been created or a blank username it gives a custom error message but continues to error out saying there is no such file found. here is the code.
Any help would be appreciated. i feel it is something that is simple but I have been looking at it for so long I can't seem to pin point it. Thank you.
1. Username
2. Password
3. Time Stamp
When creating a password it takes the username and makes the username the name of the file. Example: username: "Andrew" file: "Andrew.txt".
When I try to read the file it works great. When I put in the wrong password of the right file name it gives a custom message box. When I put in a username that has not been created or a blank username it gives a custom error message but continues to error out saying there is no such file found. here is the code.
VB.NET:
Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
If UsernameTextBox.Text = "" And PasswordTextBox.Text = "" Then
MsgBox("You must enter a username and password.")
End If
Dim user As String
user = UsernameTextBox.Text
Using sr As StreamReader = New StreamReader(user + ".txt")
If sr.ReadLine.Contains("" + ".txt") And sr.ReadLine.Contains("" + ".txt") Then
MsgBox("You must enter a username and password.")
ElseIf sr.ReadLine.Contains(UsernameTextBox.Text) And sr.ReadLine.Contains(PasswordTextBox.Text) Then
MsgBox("Yes")
Else
MsgBox("You have entered an incorrect username/password.")
End If
End Using
End Sub
Any help would be appreciated. i feel it is something that is simple but I have been looking at it for so long I can't seem to pin point it. Thank you.