Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

Importing USER:PASS txt file to Textboxes

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!
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)
[Image: Xiuymkc.png]
(Jan 19, 2018 03:07 AM)Unknown 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.
(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
[Image: Xiuymkc.png]
(Jan 19, 2018 03:07 AM)Unknown 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
It works great, thanks heaps guys!


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C] by jBarrelNov 15, 2022 02:52 PM 8 325 Nov 15, 2022 02:52 PM
Last Post: HFDone
[.NET] by MarwenSep 24, 2022 04:19 PM 10 640 Sep 24, 2022 04:19 PM
Last Post: BinaryFox
[C#] by john ronaldsadJul 28, 2022 05:01 PM 3 164 Jul 28, 2022 05:01 PM
Last Post: john ronaldsad