| | |
Simple login (read data through txt file)
![]() |
•
•
Join Date: Oct 2006
Posts: 14
Reputation:
Solved Threads: 0
HI, I am having a few problems, I want to make a simple login that will read a text file where the "username","password" will be, it will be displayed like this:
"username1","password1"
"username2","password2"
etc, I would like it so that the login form will read the data, if a user enters wrong username or wrong pass then they will get a message, so obv if you have two text boxes,
Username[____________] Password[_________________]
username1 would have to match with password1,
Anyway I need the right code to help me do this, as I have create a simple registration process that writes the username/password as above into a text file:
(registration)
"username1","password1"
"username2","password2"
etc, I would like it so that the login form will read the data, if a user enters wrong username or wrong pass then they will get a message, so obv if you have two text boxes,
Username[____________] Password[_________________]
username1 would have to match with password1,
Anyway I need the right code to help me do this, as I have create a simple registration process that writes the username/password as above into a text file:
(registration)
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Dim savefile As Long savefile = FreeFile() Open "I:\new-work\savedfile.txt" For Output As #savefile Write #savefile, (Text1.Text); (Text2.Text) Close #savefile
•
•
Join Date: Mar 2008
Posts: 3
Reputation:
Solved Threads: 0
You can try this. but I suggest, if you have several user so you should have a database of username and password. so is better to use SQL or Access to build a database for username and password.
Sadegh.mss
(registration)
Option Explicit
Dim username, password As String
Private Sub ComLogin_Click()
Open "E:\Programming\Sample\file read&write\username.txt" For Input As #1
Input #1, username
Close #1
Open "E:\Programming\Sample\file read&write\password.txt" For Input As #2
Input #2, password
Close #2
If Text1.Text <> username And Text2.Text <> password Then
MsgBox " UserName or Password is wrong"
Else
MsgBox "OK"
End If
End Sub
Private Sub ComSaveSeting_Click()
username = Text1.Text
password = Text2.Text
Open "E:\Programming\Sample\file read&write\username.txt" For Output As #1
Write #1, username
Close #1
Open "E:\Programming\Sample\file read&write\password.txt" For Output As #2
Write #2, password
Close #2
End Sub
Sadegh.mss
(registration)
Option Explicit
Dim username, password As String
Private Sub ComLogin_Click()
Open "E:\Programming\Sample\file read&write\username.txt" For Input As #1
Input #1, username
Close #1
Open "E:\Programming\Sample\file read&write\password.txt" For Input As #2
Input #2, password
Close #2
If Text1.Text <> username And Text2.Text <> password Then
MsgBox " UserName or Password is wrong"
Else
MsgBox "OK"
End If
End Sub
Private Sub ComSaveSeting_Click()
username = Text1.Text
password = Text2.Text
Open "E:\Programming\Sample\file read&write\username.txt" For Output As #1
Write #1, username
Close #1
Open "E:\Programming\Sample\file read&write\password.txt" For Output As #2
Write #2, password
Close #2
End Sub
•
•
•
•
HI, I am having a few problems, I want to make a simple login that will read a text file where the "username","password" will be, it will be displayed like this:
"username1","password1"
"username2","password2"
etc, I would like it so that the login form will read the data, if a user enters wrong username or wrong pass then they will get a message.
username1 would have to match with password1,
Anyway I need the right code to help me do this, as I have create a simple registration process that writes the username/password as above into a text file:
i think this code becomes the definite solution to your problem.
just place two textboxes and a button (with default object names) on your form for testing.
plz give me a feedback if this helps you.
place this code under Command1_Click() event and of course create a text file "user.txt" in your project folder with some sample values for testing with this code. the format should be in the following format :-
"username1","password1"
"username2","password2"
.
.
and so on...
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Dim uname As String, pwd As String Dim is_matched As Boolean If Trim(txtusername.Text) = "" Or Trim(txtpassword.Text) = "" Then MsgBox "Missing login info." txtusername.SetFocus Exit Sub End If is_matched = False Open App.Path & "\user.txt" For Input As #1 Do While Not EOF(1) Input #1, uname, pwd If Trim(uname) = Trim(txtusername.Text) And _ Trim(pwd) = Trim(txtpassword.Text) Then is_matched = True Close #1 Exit Do End If Loop Close #1 If is_matched = True Then MsgBox "Valid login." Else MsgBox "Invalid username or password." & vbCrLf & _ "Please re-try..." txtusername.Text = "" txtpassword.Text = "" txtusername.SetFocus End If
regards
Shouvik
Last edited by choudhuryshouvi; Apr 3rd, 2008 at 2:07 am.
Shouvik_The_Expert_Coder
Have a problem? Don't worry just give me a call and I'll fix it for you.
Have a problem? Don't worry just give me a call and I'll fix it for you.
•
•
Join Date: Oct 2006
Posts: 14
Reputation:
Solved Threads: 0
How to stop the same username from being written?
when I test it and register same username, it is displayed as,
"carl2k2","mypassword"
"carl2k2","mypassword"
Would have to read the username line first? and if txtusername == username in txt then should have error message
?
when I test it and register same username, it is displayed as,
"carl2k2","mypassword"
"carl2k2","mypassword"
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
If (Len(txtusername.Text) < 4) Or (Len(txtpassword.Text) < 4) Then MsgBox "Minimum length not entered" Else MsgBox "You have Registered" response = MsgBox("Would you like to login now? , Press Cancel to Exit", vbOKCancel, "Note") If response = vbOK Then 'If user clicks OK then fologin form will display fologin.Show frmreg.Visible = False 'after clicking OK then this form will not be visible Dim savefile As Long savefile = FreeFile() Open "G:\new-work\savedfile.txt" For Append As #savefile Write #savefile, (txtusername.Text); (txtpassword.Text) Close #savefile Exit Sub End If End If
Would have to read the username line first? and if txtusername == username in txt then should have error message
? Last edited by buzincarl; Apr 6th, 2008 at 3:01 pm.
ok....
try this code.
place two textboxes(txtusername,txtpasswd) and a button. no need to create the text file. it will be automatically created.
give me a feedback.
regards
Shouvik
try this code.
place two textboxes(txtusername,txtpasswd) and a button. no need to create the text file. it will be automatically created.
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Dim user As String, pwd As String Dim duplicate As Boolean duplicate = False If Dir(App.Path & "\user.txt") = "" Then GoTo adduser Else Open App.Path & "\user.txt" For Input As #1 Do While Not EOF(1) Input #1, user, pwd If Trim(user) = Trim(txtusername.Text) And Trim(pwd) = Trim(txtpasswd.Text) Then duplicate = True Close #1 Exit Do End If Loop Close #1 If duplicate = True Then MsgBox "username/password already exists." Else adduser: Open App.Path & "\user.txt" For Append As #1 Write #1, Trim(txtusername.Text), Trim(txtpasswd.Text) Close #1 MsgBox "User created." End If txtusername.Text = "" txtpasswd.Text = "" txtusername.SetFocus End If
give me a feedback.
regards
Shouvik
Shouvik_The_Expert_Coder
Have a problem? Don't worry just give me a call and I'll fix it for you.
Have a problem? Don't worry just give me a call and I'll fix it for you.
•
•
Join Date: Oct 2006
Posts: 14
Reputation:
Solved Threads: 0
hey, lol, before reading your message I was thinking that login code you made could work with this right?
anyway this all I came up with so far,
I coded label1 to = txtusername
so if uname = same as what was writtent then login is already used, although some parts are messy
, but now I read what you put, just wanted to type this if im learning it right
forgot to link it to right form(as this is test form) (txtusername.Text to frmreg.txtusername.Text)
anyway this all I came up with so far,
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Dim uname As String, pwd As String Dim is_matched As Boolean If Trim(frmreg.txtusername.Text) <> Label1.Caption Then MsgBox "should work" txtusername.SetFocus Open App.Path & "G:\College Work ------- Updated 2008 March\new-work\savedfile.txt" For Input As #1 Do While Not EOF(1) Input #1, uname If Trim(uname) = Trim(frmreg.txtusername.Text) Then is_matched = True Close #1 Exit Do End If Loop Close #1 Exit Sub End If
I coded label1 to = txtusername
so if uname = same as what was writtent then login is already used, although some parts are messy
, but now I read what you put, just wanted to type this if im learning it rightforgot to link it to right form(as this is test form) (txtusername.Text to frmreg.txtusername.Text)
Last edited by buzincarl; Apr 6th, 2008 at 4:01 pm.
•
•
Join Date: Oct 2006
Posts: 14
Reputation:
Solved Threads: 0
hey Just tried out your code and it still does duplicate username 
I had to edit some code, because when I use app.data I can't write to file unless I made it an exe,
I changed to this:
If Dir("G:\College Work ------- Updated 2008 March\new-work\test.txt") = "" Then
aha I foudn the problem, if the username and password are the same then it wont write it
, hopefulyl i can modfy it to work
so if only username exists
hehe, thanks dude, I just removed the part to check the password, I think you probably did that on purpose

I had to edit some code, because when I use app.data I can't write to file unless I made it an exe,
I changed to this:
If Dir("G:\College Work ------- Updated 2008 March\new-work\test.txt") = "" Then
aha I foudn the problem, if the username and password are the same then it wont write it
, hopefulyl i can modfy it to work
so if only username existshehe, thanks dude, I just removed the part to check the password, I think you probably did that on purpose
Last edited by buzincarl; Apr 6th, 2008 at 4:52 pm.
•
•
Join Date: Oct 2006
Posts: 14
Reputation:
Solved Threads: 0
I wanted to create a profile page, when the user is logged in their details will be presented,
I can set it so in profile it will display the username just by linking it from a previous form,
I would like to have it so all information from the username will be displayed from the line
, any way of doing that
?
I modified the code that you made and added address / postcode, etc
I can set it so in profile it will display the username just by linking it from a previous form,
I would like to have it so all information from the username will be displayed from the line
, any way of doing that
?I modified the code that you made and added address / postcode, etc
i just can't understand what exactly you are trying to do?
first you posted, you want your program to access a text file where some sort of username and password have been stored. then you will pass a set of username and password from your form's textboxes and your program should check this with corresponding to all the records stored in the text file. now if any of the pairs matches with the textbox values you will give access permission to your user.
secondly you posted, how could you make your program so that when you are creating users it won't accept duplicate username and password. it will only store such a pair which doesn't exist in the textfile.
tell me whether i'm right or wrong?
i have just given you the codes which match your request and i think regarding the issues you posted i gave correct solutions. these codes are tested in my machine and these are working perfectly.
now whatever you said in your last three posts could you please explain it more clearly? i just want a clear explanation in simple and clear english. just tell what exactly you are trying to do?
and one more thing, if its possible plz upload your existing program which you have done so far so that i can test it on my machine and give you most appropriate solutions based on the results generated by your application.
now if you don't wish to do so,
then the summary is -->
i will recommend you to use database instead of using simple textfiles. because storing sensitive data like username and password in such a textfile can be easily viewable by your users. if you use database then your coding becomes more easy and you will get more security and features that you will never get from textfiles.
just think ten times before you post another reply.
ok....
regards
Shouvik
first you posted, you want your program to access a text file where some sort of username and password have been stored. then you will pass a set of username and password from your form's textboxes and your program should check this with corresponding to all the records stored in the text file. now if any of the pairs matches with the textbox values you will give access permission to your user.
secondly you posted, how could you make your program so that when you are creating users it won't accept duplicate username and password. it will only store such a pair which doesn't exist in the textfile.
tell me whether i'm right or wrong?
i have just given you the codes which match your request and i think regarding the issues you posted i gave correct solutions. these codes are tested in my machine and these are working perfectly.
now whatever you said in your last three posts could you please explain it more clearly? i just want a clear explanation in simple and clear english. just tell what exactly you are trying to do?
and one more thing, if its possible plz upload your existing program which you have done so far so that i can test it on my machine and give you most appropriate solutions based on the results generated by your application.
now if you don't wish to do so,
then the summary is -->
i will recommend you to use database instead of using simple textfiles. because storing sensitive data like username and password in such a textfile can be easily viewable by your users. if you use database then your coding becomes more easy and you will get more security and features that you will never get from textfiles.
just think ten times before you post another reply.
ok....
regards
Shouvik
Last edited by choudhuryshouvi; Apr 7th, 2008 at 2:24 am.
Shouvik_The_Expert_Coder
Have a problem? Don't worry just give me a call and I'll fix it for you.
Have a problem? Don't worry just give me a call and I'll fix it for you.
Hi there,
Im trying to make a TXT login form for a VB6 program im making.
I want the TXT to be stored online; e.g http://daniweb.com/LOGIN.TXT
I want the LOGIN.TXT file to contain the simple login credentials.
In my program, the login is the first thing that appears on opening. There are 2 boxes (Text1.text and Text2.text) and a button (Command1)
I tried one of your earlier posted scripts choudhuryshouvi but it didnt login, everytime it said incorrect login when the login was correct. The same script didnt work if the LOGIN.TXT file was stored online.
Can anyone help me??
Thanks
David Rapley
Im trying to make a TXT login form for a VB6 program im making.
I want the TXT to be stored online; e.g http://daniweb.com/LOGIN.TXT
I want the LOGIN.TXT file to contain the simple login credentials.
In my program, the login is the first thing that appears on opening. There are 2 boxes (Text1.text and Text2.text) and a button (Command1)
I tried one of your earlier posted scripts choudhuryshouvi but it didnt login, everytime it said incorrect login when the login was correct. The same script didnt work if the LOGIN.TXT file was stored online.
Can anyone help me??
Thanks
David Rapley
![]() |
Similar Threads
- Password Protecting the add page (PHP)
- This Should be Easy for You Guys! (Linux Servers and Apache)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: Common Dialog Control
- Next Thread: query to select a range of transactions from mutiple tables respect to date??
| Thread Tools | Search this Thread |
* 6 429 2007 access activex add age application basic beginner birth bmp calculator cd cells.find click client code college component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report save search sendbyte sites sort sql sql2008 sqlserver subroutine tags textbox time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows





