Click to See Complete Forum and Search --> : user name and password thing.
Visual ßasic
Nov 24th, 1999, 09:34 AM
the first time a person open my program. it will ask them to add a name the will and then it will ask for a password.next time they open the program there name will be in a list box and it will ask for the password. how do i do this.
spandex44
Nov 24th, 1999, 03:24 PM
Hi! This probably isn't a very good way to do it but you can try. First of all, make two text files (for this example, I'm assuming they're in C:\Windows).
Name one of them Start.txt, and the other User.txt. Then create an extra form for the password and username. Call it frmUser. On that form, place two textboxes (txtName and txtPassword) and a command button. Then place this code into the Form_Load event of your main form (NOT the password/name form). I'm assuming that it's called Form1:
Dim startNum
Open "C:\Windows\Start.txt" For Input As #1
Do While Not EOF(1)
Input #1, startNum
Loop
Close #1
Me.Hide
frmUser.Show
Then place this code in the Click event of the Command Button on frmUser:
Dim usrName As String
Dim Password As String
If startNum = 0 Then
Open "C:\Windows\User.txt" For Output As #2
Write #2, txtName.Text, txtPassword.Text
Close #2
startNum = 1
Open "C:\Windows\Start.txt" For Output As #1
Write #1, startNum
Close #1
End If
If startNum = 1 Then
Open "C:\Windows\User.txt" For Input As #2
Do While Not EOF(2)
Input #2, usrName, Password
Loop
Close #1
If txtName.Text = usrName And txtPassword = Password Then
Form1.Show
Me.Hide
Else
MsgBox "Wrong Info"
End If
End If
Now the last thing you need to do is open Start.txt nad type in 0 (zero). That's it. Any time you want the user to change his name/password, set startNum = 0 and then write StartNum to Start.txt. I tried the code but it displays the other form even with the wrong password/name. It has something to do with the IF THEN statement. Try to figure out how to fix it. If you can't, then e-mail me at:
gs_enterprises@hotmail.com
Otherwise, good luck!
Alexander McAndrew
VB Zone http://gsenterprise.server101.com
spandex44
Nov 24th, 1999, 03:27 PM
I just found one mistake (not too important). Where it says Close #1 near the bottom, change that to Close #2. Good luck!
Alexander McAndrew
VB Zone http://gsenterprise.server101.com
Mark Sreeves
Nov 24th, 1999, 05:58 PM
If possible it would be nicer using a database to hold password/username pairs.
You can then easily populate your list and check the password using SQL
------------------
Mark Sreeves
Analyst Programmer
Mark.Sreeves@Softlab.co.uk
A BMW Group Company
Visual ßasic
Nov 25th, 1999, 12:19 AM
that not what i wanted and that does not work.
spandex44
Nov 25th, 1999, 01:12 AM
Sory, I guess I didn't read the question properly. You could be a little bit friendlier though. If you want, I can still help you.
------------------
Regards,
Alexander McAndrew
VB Zone
http://gsenterprise.server101.com
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.