473,419 Members | 1,605 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,419 developers and data experts.

Simple way to read Login information from text file

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.
Jul 9 '07 #1
4 9677
Killer42
8,435 Expert 8TB
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.
Jul 9 '07 #2
hariharanmca
1,977 1GB
can you able to explain this code then it'll be good to get the things clear?
Aug 4 '07 #3
carl2k2
15
How to make it read the text file is the data is printed like this

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

etc.
Apr 2 '08 #4
Killer42
8,435 Expert 8TB
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 #.
Apr 3 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

19
by: Siobhan | last post by:
Hi What is the recommended way to store a user's database credentials across the pages of a web application so that each time the database is accessed the system doesn't have to ask them for their...
10
by: serge calderara | last post by:
Dear all, I need to build a web application which will contains articles (long or short) I was wondering on what is the correct way to retrive those article on web page. In orther words, when...
0
by: Daniel Sélen Secches | last post by:
I found a good class to do a simple FTP. Very good.... I'm posting it with the message, i hope it helps someone ============================================================== Imports...
0
by: XML newbie: Urgent pls help! | last post by:
I am using VB.Net. My program is to connect to a remote IPAddress. Once, it verifies the login information it should display the SessionID and enable some button . I appreciate your help and thanku...
1
by: carmstrong | last post by:
I'm new to PHP and I'm trying to write up a simple PHP login page script to authenticate users from a flat file. I've managed to make most of it work, except that it only accepts the last user on...
1
by: bobmct | last post by:
Again: struggling to convert old-style HTML to html using css. I am trying to create a rectangular box divided into approx three vertical sections. The top section contains an image I would like...
1
by: trint | last post by:
Hi, I need to have a "remember my login" cookie if someone checks the checkbox. The checkbox's text is "Remember Me on this Computer" The login users name is their email (like): users name: ...
1
by: carl2k2 | last post by:
Ok First I have a very simple way of entering data into a form and saving that into a text file, I made two text files for username(text1) and password(text2), I would like to make a simple login...
3
by: satishknight | last post by:
Hi, Can some one tell me how to change the validation sequence for the code pasted below, actually what I want it when any one enters the wrong login information (already registered users) then it...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.