Results 1 to 3 of 3

Thread: Problems with account validation..IS there a better way to do this??

  1. #1

    Thread Starter
    Lively Member nemesys777's Avatar
    Join Date
    Nov 2001
    Posts
    103

    Question Problems with account validation..IS there a better way to do this??

    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:
    Code:
    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..

  2. #2
    Addicted Member wolfofthenorth's Avatar
    Join Date
    Jan 2001
    Location
    Tatooine
    Posts
    169
    Here's a couple of other approaches similar to what you already have.

    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
    That which does not kill us, only makes us stronger.

  3. #3
    Addicted Member wolfofthenorth's Avatar
    Join Date
    Jan 2001
    Location
    Tatooine
    Posts
    169
    You could also try the readline method of the streamreader, or read and write the information to the registry.
    That which does not kill us, only makes us stronger.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width