PDA

Click to See Complete Forum and Search --> : Problems with account validation..IS there a better way to do this??


nemesys777
May 22nd, 2002, 11:48 AM
Im trying to search a text file and first find the user inputted name. Compare that to the text file, if it finds the name in the file, then check the password...compare...If all good than AccountOK() else Accountbad()
The code I have currently searches the text file for the user inputted "name"..if it finds the name in the textfile, then it says If Index of "name" is >0 Then check password....
If I just check for the "name" the code works fine, but if I add the passcheck code it then always returns Accountbad() Even if the user name and password are correct.... IS there a better way to search for the actual name in the textfile and not just if the index is >0...And then the same for the password...preferably MOVE one line down from the found user name and then check that line..My text file format is like this:::
Account 1
Name = JoeBob
Pass = whatup

My code so far is this:

Public Sub accountvalidation(ByVal name As String, ByVal pass As String)
Dim path As String = Application.StartupPath & "\accounts.txt"
Dim data As String, n As Integer, p As Integer
accounts = New StreamReader(path)
data = accounts.ReadToEnd
n = data.IndexOf(name)
If n > 0 Then
p = data.IndexOf(pass)
If p > 0 Then
accountok()
Else
accountbad()
End If
Else : accountbad()
End If

End Sub


I know this is flawed...just can't figure out a better way to do this..Thanks in advance..

wolfofthenorth
May 23rd, 2002, 03:14 PM
Here's a couple of other approaches similar to what you already have. :D

If data.IndexOf(Name) > 0 AndAlso data.IndexOf(pass) > 0 Then
accountok()
Else
accountbad()
End If


p = data.IndexOf(Name)
If p > 0 AndAlso data.Substring(p + Name.Length + 1, pass.Length) = pass Then
accountok
else
accountbad
End If

wolfofthenorth
May 23rd, 2002, 03:19 PM
You could also try the readline method of the streamreader, or read and write the information to the registry.