Simple login (read data through txt file)

Reply

Join Date: Oct 2006
Posts: 14
Reputation: buzincarl is an unknown quantity at this point 
Solved Threads: 0
buzincarl buzincarl is offline Offline
Newbie Poster

Simple login (read data through txt file)

 
0
  #1
Apr 2nd, 2008
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)

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Dim savefile As Long
  2. savefile = FreeFile()
  3. Open "I:\new-work\savedfile.txt" For Output As #savefile
  4. Write #savefile, (Text1.Text); (Text2.Text)
  5. Close #savefile
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 3
Reputation: sadeghit is an unknown quantity at this point 
Solved Threads: 0
sadeghit sadeghit is offline Offline
Newbie Poster

Re: Simple login (read data through txt file)

 
0
  #2
Apr 2nd, 2008
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
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 537
Reputation: choudhuryshouvi is an unknown quantity at this point 
Solved Threads: 49
choudhuryshouvi's Avatar
choudhuryshouvi choudhuryshouvi is offline Offline
Posting Pro

Re: Simple login (read data through txt file)

 
0
  #3
Apr 3rd, 2008
Originally Posted by buzincarl View Post
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:
try the following code.
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)
  1. Dim uname As String, pwd As String
  2. Dim is_matched As Boolean
  3.  
  4. If Trim(txtusername.Text) = "" Or Trim(txtpassword.Text) = "" Then
  5. MsgBox "Missing login info."
  6. txtusername.SetFocus
  7. Exit Sub
  8. End If
  9.  
  10. is_matched = False
  11.  
  12. Open App.Path & "\user.txt" For Input As #1
  13. Do While Not EOF(1)
  14. Input #1, uname, pwd
  15. If Trim(uname) = Trim(txtusername.Text) And _
  16. Trim(pwd) = Trim(txtpassword.Text) Then
  17. is_matched = True
  18. Close #1
  19. Exit Do
  20. End If
  21. Loop
  22. Close #1
  23.  
  24. If is_matched = True Then
  25. MsgBox "Valid login."
  26. Else
  27. MsgBox "Invalid username or password." & vbCrLf & _
  28. "Please re-try..."
  29. txtusername.Text = ""
  30. txtpassword.Text = ""
  31. txtusername.SetFocus
  32. 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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 14
Reputation: buzincarl is an unknown quantity at this point 
Solved Threads: 0
buzincarl buzincarl is offline Offline
Newbie Poster

Re: Simple login (read data through txt file)

 
0
  #4
Apr 6th, 2008
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"

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. If (Len(txtusername.Text) < 4) Or (Len(txtpassword.Text) < 4) Then
  2. MsgBox "Minimum length not entered"
  3. Else
  4. MsgBox "You have Registered"
  5. response = MsgBox("Would you like to login now? , Press Cancel to Exit", vbOKCancel, "Note")
  6.  
  7. If response = vbOK Then 'If user clicks OK then fologin form will display
  8. fologin.Show
  9. frmreg.Visible = False 'after clicking OK then this form will not be visible
  10.  
  11.  
  12. Dim savefile As Long
  13. savefile = FreeFile()
  14. Open "G:\new-work\savedfile.txt" For Append As #savefile
  15. Write #savefile, (txtusername.Text); (txtpassword.Text)
  16. Close #savefile
  17. Exit Sub
  18.  
  19.  
  20. End If
  21. 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.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 537
Reputation: choudhuryshouvi is an unknown quantity at this point 
Solved Threads: 49
choudhuryshouvi's Avatar
choudhuryshouvi choudhuryshouvi is offline Offline
Posting Pro

Re: Simple login (read data through txt file)

 
0
  #5
Apr 6th, 2008
ok....
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)
  1. Dim user As String, pwd As String
  2. Dim duplicate As Boolean
  3.  
  4. duplicate = False
  5.  
  6. If Dir(App.Path & "\user.txt") = "" Then
  7. GoTo adduser
  8. Else
  9. Open App.Path & "\user.txt" For Input As #1
  10. Do While Not EOF(1)
  11. Input #1, user, pwd
  12. If Trim(user) = Trim(txtusername.Text) And Trim(pwd) = Trim(txtpasswd.Text) Then
  13. duplicate = True
  14. Close #1
  15. Exit Do
  16. End If
  17. Loop
  18. Close #1
  19.  
  20. If duplicate = True Then
  21. MsgBox "username/password already exists."
  22. Else
  23. adduser:
  24. Open App.Path & "\user.txt" For Append As #1
  25. Write #1, Trim(txtusername.Text), Trim(txtpasswd.Text)
  26. Close #1
  27. MsgBox "User created."
  28. End If
  29.  
  30. txtusername.Text = ""
  31. txtpasswd.Text = ""
  32. txtusername.SetFocus
  33. 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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 14
Reputation: buzincarl is an unknown quantity at this point 
Solved Threads: 0
buzincarl buzincarl is offline Offline
Newbie Poster

Re: Simple login (read data through txt file)

 
0
  #6
Apr 6th, 2008
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,

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Dim uname As String, pwd As String
  2. Dim is_matched As Boolean
  3.  
  4. If Trim(frmreg.txtusername.Text) <> Label1.Caption Then
  5. MsgBox "should work"
  6. txtusername.SetFocus
  7.  
  8. Open App.Path & "G:\College Work ------- Updated 2008 March\new-work\savedfile.txt" For Input As #1
  9. Do While Not EOF(1)
  10. Input #1, uname
  11. If Trim(uname) = Trim(frmreg.txtusername.Text) Then
  12. is_matched = True
  13. Close #1
  14. Exit Do
  15. End If
  16. Loop
  17. Close #1
  18. Exit Sub
  19. 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 right


forgot 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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 14
Reputation: buzincarl is an unknown quantity at this point 
Solved Threads: 0
buzincarl buzincarl is offline Offline
Newbie Poster

Re: Simple login (read data through txt file)

 
0
  #7
Apr 6th, 2008
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
Last edited by buzincarl; Apr 6th, 2008 at 4:52 pm.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 14
Reputation: buzincarl is an unknown quantity at this point 
Solved Threads: 0
buzincarl buzincarl is offline Offline
Newbie Poster

How to display data

 
0
  #8
Apr 6th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 537
Reputation: choudhuryshouvi is an unknown quantity at this point 
Solved Threads: 49
choudhuryshouvi's Avatar
choudhuryshouvi choudhuryshouvi is offline Offline
Posting Pro

Re: Simple login (read data through txt file)

 
0
  #9
Apr 7th, 2008
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
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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 3
Reputation: frostyzonec is an unknown quantity at this point 
Solved Threads: 0
frostyzonec's Avatar
frostyzonec frostyzonec is offline Offline
Newbie Poster

Re: Simple login (read data through txt file)

 
0
  #10
Apr 8th, 2008
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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC