Hack Forums
[.NET] Importing USER:PASS txt file to Textboxes - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [.NET] Importing USER:PASS txt file to Textboxes (/showthread.php?tid=5787044)



Importing USER:PASS txt file to Textboxes - ThatAlbinoFrog - Jan 19, 2018

How would I got about importing a txt file with login details formatted like - 

    USERNAME1:PASSWORD1
    USERNAME2:PASSWORD2
    USERNAME3:PASSWORD3

I want to import the text file, then have the USER go into one textbox and the PASSWORD go into the other. Sorry if this is worded poorly, I'm pretty new to coding, and I'm completely lost when it comes to this. 

This is kinda what I'm trying to do in a really dumb way - 

Code
                        OpenFileDialog1.ShowDialog()
                    TextBox1.text = (IO.File.ReadAllLines(OpenFileDialog1.FileName))
        if TextBox1.text contains (":") then 
        TextBox2.text = (Text After The :)
        TextBox1.text = (Text Before the :)
    Do all the functions with that login
    Then read the next line and use that pair login details (USERNAME2:PASSWORD2)


Thanks heaps!


RE: Importing USER:PASS txt file to Textboxes - Unknown - Jan 19, 2018

I'd say the easiest way to do something like this would be with string.Split

Example:
Code
Dim combo As String = "username:password"
Dim username = combo.Split(","c)(0)
Dim password = combo.Split(","c)(1)
Here's an example and result:
Spoiler (Click to View)


RE: Importing USER:PASS txt file to Textboxes - Ninja - Jan 19, 2018

(Jan 19, 2018 03:07 AM)Cynn. Wrote:  I'd say the easiest way to do something like this would be with string.Split

Example:
Code
Dim combo As String = "username:password"
Dim username = combo.Split(","c)(0)
Dim password = combo.Split(","c)(1)
Here's an example and result:
Spoiler (Click to View)

Though it would be best to save the array when you split so you don't have to keep splitting. Like this:
Code
Dim combo As String = "username:password"
Dim splitCombo As String = combo.Split(':', 2)
Dim username As String = splitCombo(0)
Dim password As String = splitCombo(1)
Also it is important to set the maximum number of substrings that the split method returns to 2, as some passwords can contain a ':' and without specifying this it would mess up.


RE: Importing USER:PASS txt file to Textboxes - Unknown - Jan 19, 2018

(Jan 19, 2018 04:00 AM)Ninja Wrote:  Though it would be best to save the array when you split so you don't have to keep splitting. Like this:
Code
Dim combo As String = "username:password"
Dim splitCombo As String = combo.Split(':', 2)
Dim username As String = splitCombo(0)
Dim password As String = splitCombo(1)
Also it is important to set the maximum number of substrings that the split method returns to 2, as some passwords can contain a ':' and without specifying this it would mess up.
^ I didn't even think of that, thanks for adding onto it Ninja


RE: Importing USER:PASS txt file to Textboxes - ThatAlbinoFrog - Jan 19, 2018

(Jan 19, 2018 03:07 AM)Cynn. Wrote:  I'd say the easiest way to do something like this would be with string.Split

Example:
Code
Dim combo As String = "username:password"
Dim username = combo.Split(","c)(0)
Dim password = combo.Split(","c)(1)
Here's an example and result:
Spoiler (Click to View)

(Jan 19, 2018 04:00 AM)Ninja Wrote:  Though it would be best to save the array when you split so you don't have to keep splitting. Like this:
Code
Dim combo As String = "username:password"
Dim splitCombo As String = combo.Split(':', 2)
Dim username As String = splitCombo(0)
Dim password As String = splitCombo(1)
Also it is important to set the maximum number of substrings that the split method returns to 2, as some passwords can contain a ':' and without specifying this it would mess up.

Thanks for the help guys! I'll test it out tomorrow when I'm with my laptop


RE: Importing USER:PASS txt file to Textboxes - ThatAlbinoFrog - Jan 19, 2018

It works great, thanks heaps guys!