9 Replies - 349 Views - Last Post: 15 February 2013 - 09:06 PM Rate Topic: -----

#1 alexrunkles  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 26
  • Joined: 17-October 12

Separating delimited text into strings for an account list

Posted 15 February 2013 - 06:39 PM

I can't manage to figure out how to separate delimited text into strings. This is the format of the text "Admin:Pass". I need the first part into a string for checking the username and the second part into a string for check the password. I need it to read line by line and for each line check the username and password where they must both match for the login to be successful. The usernames and passwords are stored on an online text upload site for me to add new ones as people get the program. Here's what I have so far:
 Imports System.IO
Imports System.Management

Public Class LoginWindow

    Private Sub LoginWindow_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub btnQuit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnQuit.Click
        Me.Close()
    End Sub


    Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
        Dim Request As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create(My.Settings.LoginInfo)
        Dim Response As System.Net.HttpWebResponse = Request.GetResponse()
        Dim SR As System.IO.StreamReader = New System.IO.StreamReader(Response.GetResponseStream)
        Dim LoginAdded As String = SR.ReadToEnd
        Dim ThisUser As String = txtUsername.Text()
        If LoginAdded.Contains(ThisUser) Then

        End If

        Dim ThisPass As String = txtPassword.Text()
    End Sub
End Class 


Is This A Good Question/Topic? 0
  • +

Replies To: Separating delimited text into strings for an account list

#2 IronRazer  Icon User is offline

  • D.I.C Addict

Reputation: 236
  • View blog
  • Posts: 781
  • Joined: 01-February 13

Re: Separating delimited text into strings for an account list

Posted 15 February 2013 - 06:51 PM

Have you tried using (Split) like this.

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim mystring As String = "TheName:ThePassWord"
        'Use (Split) to seperate
        Dim splitstring() As String = mystring.Split(":")
        'Show both strings
        MessageBox.Show(splitstring(0) & "   " & splitstring(1))
    End Sub


Was This Post Helpful? 0
  • +
  • -

#3 alexrunkles  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 26
  • Joined: 17-October 12

Re: Separating delimited text into strings for an account list

Posted 15 February 2013 - 07:03 PM

How can I just read one line, check it, then if it's not a valid login read the next line, check that and so on?
Was This Post Helpful? 0
  • +
  • -

#4 IronRazer  Icon User is offline

  • D.I.C Addict

Reputation: 236
  • View blog
  • Posts: 781
  • Joined: 01-February 13

Re: Separating delimited text into strings for an account list

Posted 15 February 2013 - 07:41 PM

View Postalexrunkles, on 15 February 2013 - 09:03 PM, said:

How can I just read one line, check it, then if it's not a valid login read the next line, check that and so on?


Let me just make sure i understand. You want to read (SR)the LoginAdded line by line and then compare it to (ThisUser) ?

This post has been edited by IronRazer: 15 February 2013 - 07:53 PM

Was This Post Helpful? 0
  • +
  • -

#5 alexrunkles  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 26
  • Joined: 17-October 12

Re: Separating delimited text into strings for an account list

Posted 15 February 2013 - 07:56 PM

Yes, I want to compare the part before the ":" to ThisUser and the part after the ":" to ThisPass but I want to check every line, line by line until it finds the correct match or doesn't.
Was This Post Helpful? 0
  • +
  • -

#6 IronRazer  Icon User is offline

  • D.I.C Addict

Reputation: 236
  • View blog
  • Posts: 781
  • Joined: 01-February 13

Re: Separating delimited text into strings for an account list

Posted 15 February 2013 - 08:18 PM

View Postalexrunkles, on 15 February 2013 - 09:56 PM, said:

Yes, I want to compare the part before the ":" to ThisUser and the part after the ":" to ThisPass but I want to check every line, line by line until it finds the correct match or doesn't.


I did a little work to it and put some comments in there so you can understand what is going on. Try it out and see if it does what you want.

    Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
        Dim Request As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create(My.Settings.LoginInfo)
        Dim Response As System.Net.HttpWebResponse = Request.GetResponse()
        Dim SR As System.IO.StreamReader = New System.IO.StreamReader(Response.GetResponseStream)

        Dim ThisUser As String = txtUsername.Text()
        Dim ThisPass As String = txtPassword.Text()
        Dim match As Boolean = False

        'read one line
        Dim LoginAdded As String = SR.ReadLine '

        'if it is not end of stream then continue
        While (Not LoginAdded = SR.EndOfStream)
            'split loginadded into name & pass
            Dim nameandpass As String() = LoginAdded.Split(":")

            'Check if name and pass are a match
            If nameandpass(0) = ThisUser And nameandpass(1) = ThisPass Then
                match = True
                Exit While 'If matched then stop checking
            End If

            'read the next loginadded
            LoginAdded = SR.ReadLine
        End While

        SR.Close() 'Close the streamreader

        If match = True Then
            'It was found
        Else
            'It was not found
        End If

    End Sub


Was This Post Helpful? 0
  • +
  • -

#7 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1046
  • View blog
  • Posts: 4,072
  • Joined: 02-July 08

Re: Separating delimited text into strings for an account list

Posted 15 February 2013 - 08:28 PM

Diff approach:

While Not sr.EndOfStream
  Dim userpass() As String = sr.Readline.Split(":"c)
  'check and if passes Exit While
End While

Was This Post Helpful? 0
  • +
  • -

#8 IronRazer  Icon User is offline

  • D.I.C Addict

Reputation: 236
  • View blog
  • Posts: 781
  • Joined: 01-February 13

Re: Separating delimited text into strings for an account list

Posted 15 February 2013 - 08:40 PM

OOOOPS.. I just seen i screwed up this line
Dim nameandpass As String() = LoginAdded.Split(":")


It Should Be
Dim nameandpass() As String = LoginAdded.Split(":")

Was This Post Helpful? 0
  • +
  • -

#9 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1046
  • View blog
  • Posts: 4,072
  • Joined: 02-July 08

Re: Separating delimited text into strings for an account list

Posted 15 February 2013 - 08:45 PM

View PostIronRazer, on 15 February 2013 - 08:40 PM, said:

OOOOPS.. I just seen i screwed up this line
Dim nameandpass As String() = LoginAdded.Split(":")


It Should Be
Dim nameandpass() As String = LoginAdded.Split(":")

There is no diff between your declarations.

This part will not work: While (Not LoginAdded = SR.EndOfStream) LoginAdded should never = sr.EndOfStream.
Was This Post Helpful? 0
  • +
  • -

#10 IronRazer  Icon User is offline

  • D.I.C Addict

Reputation: 236
  • View blog
  • Posts: 781
  • Joined: 01-February 13

Re: Separating delimited text into strings for an account list

Posted 15 February 2013 - 09:06 PM

Yes you are correct. I guess i am having a brain fart day. It has been this way all day. I am glad you where here to catch it. So it should be like this :
        'if it is not end of stream then continue
        While Not SR.EndOfStream
            'read one line
            Dim LoginAdded As String = SR.ReadLine

            'split loginadded into name & pass
            Dim nameandpass() As String = LoginAdded.Split(":")

            'Check if name and pass are a match
            If nameandpass(0) = ThisUser And nameandpass(1) = ThisPass Then
                match = True
                Exit While 'If matched then stop checking
            End If

        End While



I was just trying to break up the readline and split to make it a little more easy to understand what was happening.

This post has been edited by IronRazer: 15 February 2013 - 09:08 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1