Connecting Tech Pros Worldwide Forums | Help | Site Map

vb.net 2003 express edition . help with password protecting

Newbie
 
Join Date: Sep 2007
Posts: 19
#1: Oct 7 '07
-----------------------------------------------------------------------QUESTION
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
--------------------------------------------------------------------------ANSWER
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

Code:
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 SubThis 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.


Code:
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 TryNow 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

-------------------------------------------------------------------------------------NEEDED
ok firstly i posted about my idea online....
someone posted back sayin the answer 2 my problem however,
1.
"Here is some code that shows you how to read each individual line in the file."
i dont understand what he means after this sentence in the answer part.
2.
when the user clicks save and the data is saved into the text file i want you 2 be able to save multiply logins not just 1.
3.
what code would i use 2 search a login using a textbox?
jamesd0142's Avatar
Needs Regular Fix
 
Join Date: Sep 2007
Location: Wales
Posts: 467
#2: Oct 8 '07

re: vb.net 2003 express edition . help with password protecting


Lets break this down a little... 1 at a time.

searching a textbox...

I assume you mean look into the database and see if the username entered existes in the database... right?

So...

1. You connect to a database...
2. run your query (check if Username.text is in the database...)
3. if it is check the correspoding password... if correct do something

is this along the lines of what you require?

Thanks James
debasisdas's Avatar
Moderator
 
Join Date: Dec 2006
Location: Bangalore ,India
Posts: 7,508
#3: Oct 8 '07

re: vb.net 2003 express edition . help with password protecting


Question moved to .NET Forum.
Plater's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 7,161
#4: Oct 8 '07

re: vb.net 2003 express edition . help with password protecting


I don't think your file IO is quite right.
the format is
System.Io.File.WriteAllText(filename, text-to-write);

You should have a common format for writing your data. Possibly CSV style:
<website>, <username>, <password>
<website>, <username>, <password>
<website>, <username>, <password>

Which can be read and scanned easily.
Reply