473,574 Members | 2,884 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Simple way to read Login information from text file

16 New Member
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

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
  3. Private Sub Form_Load()
  4. UnCheck = False
  5. PwCheck = False
  7. nFileNum = FreeFile
  9. Open "C:\Documents and Settings\Matt\My Documents\testing.txt" For Input As nFileNum
  10. lLineCount = 1
  12. NumLine = 0
  13. LCount = 1
  14. UnPw = 0
  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
  27. End Sub
  28. Private Sub cmdCancel_Click()
  29.     Me.Hide
  30.     End
  31. End Sub
  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
  42.     If txtPassword = UInfo(UserNum, 2) Then PwCheck = True
  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
  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 9706
8,435 Recognized Expert Expert
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
1,977 Top Contributor
can you able to explain this code then it'll be good to get the things clear?
Aug 4 '07 #3
15 New Member
How to make it read the text file is the data is printed like this

"username1","pa ssword1"
"username2","pa ssword2"

Apr 2 '08 #4
8,435 Recognized Expert Expert
How to make it read the text file is the data is printed like this
"username1","pa ssword1"
"username2","pa ssword2"
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

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 username and password again We have previously stored these in a session variable (encrypted) and retrieved from their - but are worried about the...
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 there is such information to be displayed are they coming from imported files, database ? Where and how this type of information is stored ? What...
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 System.Net
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 in advance When I run the pgm , I get the error: Can't parse login information. Object Reference not set to an instance of an object. I have...
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 the user/password file, and I'm not sure why. (I.e. the user.txt file is: user1:pass1 user2:pass2 user3:pass3 and it only works for...
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 on the extreme left of the box, the text centered in the reamaining space in that section. The center third contains two lines prompting for a...
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: trinity@gmail.com password: windintrees If the cookie exists, open and read if it has a "1" to load the login information, or "0" for no...
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 with the outcome out this, Code for Registration: Dim savefile As Long savefile = FreeFile() Open "I:\College Work ------- Updated 2008...
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 has to tell then them its wrong information but currently it takes then to a next page and then tells them its incorrect information. This is tedious...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.