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
9 Replies - 163 Views - Last Post: 15 February 2013 - 09:06 PM
#1
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:
Replies To: Separating delimited text into strings for an account list
#2
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
#3
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?
#4
Re: Separating delimited text into strings for an account list
Posted 15 February 2013 - 07:41 PM
alexrunkles, 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
#5
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.
#6
Re: Separating delimited text into strings for an account list
Posted 15 February 2013 - 08:18 PM
alexrunkles, 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
#7
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
#8
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
It Should Be
Dim nameandpass As String() = LoginAdded.Split(":")
It Should Be
Dim nameandpass() As String = LoginAdded.Split(":")
#9
Re: Separating delimited text into strings for an account list
Posted 15 February 2013 - 08:45 PM
IronRazer, on 15 February 2013 - 08:40 PM, said:
OOOOPS.. I just seen i screwed up this line
It Should Be
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.
#10
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 :
I was just trying to break up the readline and split to make it a little more easy to understand what was happening.
'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
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote




|