Save website usernames and passwords

Invisionsoft

Well-known member
Joined
Apr 20, 2007
Messages
64
Location
United Kingdom
Programming Experience
1-3
hi i am really stuck with this and its only a small problem.
i want to be able to type .........
dsfsjfjsjjfs in User Box
fjdjskfjds in password box
www.thescripts.com in website box

then i want to have a button which says "save" which then saves the 3 above pieces of text into a notepad file.
So like I said I want to be able to type a login, password and website in the 3 textboxes then click a button which saves it into my .txt file.

Just make any required adjustments to do this. I am really confused with this so any help would be appreciated.
this has really confused me so please help :)

Code: ( vbnet )
1.
Public Class Form1
Dim Login As String
Dim Password As String

Dim Website As String
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
System.IO.File.WriteAllText("Password.txt", "C:\Documents and Settings\Admin\My Documents\Password.txt")
End Sub
Private Sub AddNewLoginToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddNewLoginToolStripMenuItem.Click
End Sub
End Class

also after i want to have a search box where you type in like www.thescripts into 1 box which then finds you the user name and password for that website.wot would i do here?



if you dont have much time just help me figure out where iam going wrong on the first part then leave the search problem untill you have some time :)





regards

george
 
Step 1. Create a new windows form
Step 2. Add 3 Text box's from the Toolbox to the form (I am assumign the names are textbox1,textbox2,textbox3)
Step 3. Add a save button
Step 4. Double Click the save button to bring you into the code

use this code
VB.NET:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim fs As System.IO.FileStream = New System.IO.FileStream("C:\Myfile.txt", IO.FileMode.OpenOrCreate)
        Dim sw As System.IO.StreamWriter = New System.IO.StreamWriter(fs)
        'Note vbcrlf just means I am adding a line feed to start the next line
        sw.Write(Me.textbox1.Text & vbCrLf) 'Text box 1 has the Login Name
        sw.Write(Me.textbox2.Text & vbCrLf) 'Text box 1 has the Login Name
        sw.Write(Me.textbox3.Text & vbCrLf) 'Text box 1 has the Login Name
        sw.Close()
        fs.Close()
    End Sub

This will add the info every time you click save to the file. If you want to read the file you do the same thing, except use the System.IO.StreamReade object. You will need to look up it's funcitonality.

Here is some code that shows you how to read each individual line in the file.

VB.NET:
Dim sr As system.io.StreamReader = New system.io.StreamReader("C:\myfile.txt")

Try


Do While True
Dim s As String = sr.ReadLine()
If s Is Nothing Then
Exit Do
Else
' Change this to do whatever you want with the line.
msgbox(s)
End If
Loop

Finally
If Not sr Is Nothing Then
sr.Close()
End If
End Try

Now with that being said, it is possible to code this and make it work fairly easy. However the correct approach would be to store this as a delimited file, or a xml file.

Look up this online, but hopfully this will give you a start
 
Back
Top