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
- Username1
- Password1
- Username2
- Password2
- Username3
- Password3
Now, paste this code into your Login form.
Expand|Select|Wrap|Line Numbers
- 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
- Private Sub Form_Load()
- UnCheck = False
- PwCheck = False
- nFileNum = FreeFile
- Open "C:\Documents and Settings\Matt\My Documents\testing.txt" For Input As nFileNum
- lLineCount = 1
- NumLine = 0
- LCount = 1
- UnPw = 0
- Do While Not EOF(nFileNum)
- Line Input #nFileNum, sText
- LCount = LCount + 1
- If LCount Mod 2 <> 0 Then UnPw = 2
- If LCount Mod 2 = 0 Then
- NumLine = NumLine + 1
- UnPw = 1
- End If
- UInfo(NumLine, UnPw) = sText
- Loop
- End Sub
- Private Sub cmdCancel_Click()
- Me.Hide
- End
- End Sub
- Private Sub cmdOK_Click()
- 'check for correct password
- For x = 1 To LCount
- If txtUserName = UInfo(x, 1) Then
- UnCheck = True
- UserNum = x
- End If
- Next x
- If txtPassword = UInfo(UserNum, 2) Then PwCheck = True
- If txtUserName = "" Then
- MsgBox "Invalid Username or Password, try again!", , "Login"
- txtPassword = ""
- txtPassword.SetFocus
- SendKeys "{Home}+{End}"
- ElseIf txtPassword = "" Then
- MsgBox "Invalid Username or Password, try again!", , "Login"
- txtPassword = ""
- txtPassword.SetFocus
- SendKeys "{Home}+{End}"
- ElseIf UnCheck And PwCheck = True Then
- MAINFORM.Visible = True
- Me.Enabled = False
- Me.Hide
- Else
- MsgBox "Invalid Username or Password, try again!", , "Login"
- txtPassword = ""
- txtPassword.SetFocus
- SendKeys "{Home}+{End}"
- End If
- End Sub
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.