Connecting Tech Pros Worldwide Help | Site Map

Simple way to read Login information from text file

  #1  
Old July 9th, 2007, 01:30 AM
Newbie
 
Join Date: Nov 2006
Posts: 16
This is my first tutorial, so if there are any mistakes please forgive me =).

This will show you a very simple way to read your Login information from an outside text file.

What you need:
1. Add a new "Login Dialog" form to your project.
2. Completely erase the code inside of it, but keep the interface.
3. Create a text file listing your usernames and passwords one line after the other.

Your text file should look like this (without the numbers in front of the names):

Expand|Select|Wrap|Line Numbers
  1. Username1
  2. Password1
  3. Username2
  4. Password2
  5. Username3
  6. Password3
Etc...

Now, paste this code into your Login form.
Expand|Select|Wrap|Line Numbers
  1. Dim nFileNum As Integer, UInfo(999, 2) As String, sNextLine As String, lLineCount As Long, NumLine As Integer, LCount As Integer, UnPw As Integer, UnCheck As Boolean, PwCheck As Boolean, UserNum As Integer
  2.  
  3. Private Sub Form_Load()
  4. UnCheck = False
  5. PwCheck = False
  6.  
  7. nFileNum = FreeFile
  8.  
  9. Open "C:\Documents and Settings\Matt\My Documents\testing.txt" For Input As nFileNum
  10. lLineCount = 1
  11.  
  12. NumLine = 0
  13. LCount = 1
  14. UnPw = 0
  15.  
  16. Do While Not EOF(nFileNum)
  17.    Line Input #nFileNum, sText
  18.    LCount = LCount + 1
  19.    If LCount Mod 2 <> 0 Then UnPw = 2
  20.    If LCount Mod 2 = 0 Then
  21.    NumLine = NumLine + 1
  22.    UnPw = 1
  23.    End If
  24.   UInfo(NumLine, UnPw) = sText
  25. Loop
  26.  
  27. End Sub
  28. Private Sub cmdCancel_Click()
  29.     Me.Hide
  30.     End
  31. End Sub
  32.  
  33. Private Sub cmdOK_Click()
  34.     'check for correct password
  35.     For x = 1 To LCount
  36.         If txtUserName = UInfo(x, 1) Then
  37.         UnCheck = True
  38.         UserNum = x
  39.         End If
  40.     Next x
  41.  
  42.     If txtPassword = UInfo(UserNum, 2) Then PwCheck = True
  43.  
  44.     If txtUserName = "" Then
  45.       MsgBox "Invalid Username or Password, try again!", , "Login"
  46.         txtPassword = ""
  47.         txtPassword.SetFocus
  48.         SendKeys "{Home}+{End}"
  49.     ElseIf txtPassword = "" Then
  50.        MsgBox "Invalid Username or Password, try again!", , "Login"
  51.         txtPassword = ""
  52.         txtPassword.SetFocus
  53.         SendKeys "{Home}+{End}"
  54.     ElseIf UnCheck And PwCheck = True Then
  55.         MAINFORM.Visible = True
  56.         Me.Enabled = False
  57.         Me.Hide
  58.     Else
  59.         MsgBox "Invalid Username or Password, try again!", , "Login"
  60.         txtPassword = ""
  61.         txtPassword.SetFocus
  62.         SendKeys "{Home}+{End}"
  63.     End If
  64.  
  65. End Sub
Now, you are almost done.

1. Go to line 9 and change the filepath to where your text file resides.
2. Go to line 55 and change "MAINFORM" to your form that you would like to show.

Now you SHOULD be done! The way the program is written, you may have up to 999 sets of usernames and passwords.

The only problem with this is that if somebody knows where your text file is, they have all your passwords! Luckily the program I am using this for just HAPPENS to be an encryption program, so I can simply encrypt the text file. Once I have finished this I will repost on how it is done.



  #2  
Old July 9th, 2007, 04:05 AM
Moderator
 
Join Date: Oct 2006
Location: Australia
Posts: 7,750

re: Simple way to read Login information from text file


Thanks for that, ldpfrog

When I have the time one of these weekends, I may edit the article, just for consistency with various others here - one of the benefits of being a moderator. :)

I'd like to point out though, in any such case, the most basic security measure would be to store the encrypted version of each password in your file, not the "clear" version. That way, reading the file will not tell people your passwords, unless they figure out how to decrypt them. And if they wanted to edit the file to allow themselves access, they would have to encrypt their password, your way, for it to work. Certainly not impregnable, but definitely tougher than just reading the file.
  #3  
Old August 4th, 2007, 12:14 PM
hariharanmca's Avatar
Lives Here
 
Join Date: Dec 2006
Location: Banglore/India
Posts: 1,992

re: Simple way to read Login information from text file


can you able to explain this code then it'll be good to get the things clear?
  #4  
Old April 2nd, 2008, 02:49 PM
Newbie
 
Join Date: Mar 2008
Posts: 15

re: Simple way to read Login information from text file


How to make it read the text file is the data is printed like this

"username1","password1"
"username2","password2"

etc.
  #5  
Old April 3rd, 2008, 07:39 AM
Moderator
 
Join Date: Oct 2006
Location: Australia
Posts: 7,750

re: Simple way to read Login information from text file


Quote:
Originally Posted by carl2k2
How to make it read the text file is the data is printed like this
"username1","password1"
"username2","password2"
I'd look into using the Input # statement, instead of Line Input #.
Reply


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Make a File Download Script with Perl KevinADC insights 1 December 4th, 2008 06:44 AM
Session handling, login across all subdomains Josh answers 9 August 1st, 2008 05:55 AM
How to have multiple worker threads submit to one final processing queue? - HELP James Radke answers 6 November 20th, 2005 01:16 AM
[REPOST] Using CDO from C# Noonan, Derek answers 4 November 16th, 2005 12:25 PM