473,387 Members | 1,516 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Reading in Login info from outside

16
I am currently writing a very simple encryption program for my friends and myself. I'm still learning VB, but am very familiar with programming itself. This is all irrelevant though, because this technique could be applied to any program which requires logging in.

I would like to be able to make a file (just a basic text file or spreadsheet to start would be fine) with Usernames and Passwords listed which will be accepted into my program. I currently just use If statements for two or three users, but will eventually probably distribute this to more of my friends, in which it would be much easier to host some sort of file for the program to connect to and read from.

I understand how to use the Login information, I am just not familiar with reading in information with VB. Once that is working I'd also like a suggestion as to how I could make it so only the program (or some sort of password protection) could access the login information file.

If we get this far, I would also like to be able to host it (which I can do) and have my program read from it on the web, so I could just change the file from my computer and it would work with whoever is using the software.

Thanks alot!
Frog
Jul 1 '07 #1
9 1355
Killer42
8,435 Expert 8TB
If you have a look at the "Index of articles" at the top of the VB forum, there are links to a couple of samples showing how to read a text file in VB.

I don't know how you can restrict access to the file, but one simple precaution would be to store the passwords in their encrypted form. That way, if someone edits the file, unless they know your encryption method, the most they can do is to stop it working by messing up the stored details. If you encrypt the entire file contents, or at least include some sort of checksum, then your program could detect that it has been modified and refuse to run.
Jul 2 '07 #2
ldpfrog
16
I did see that but I don't understand how to use it. It essentially hands you a chunk of code and doesn't tell you how to use it

I have also been looking online and many are saying to use ADO, where you would use excel as opposed to a text file. I have been screwing around with this with no success =/.
Jul 2 '07 #3
danp129
323 Expert 256MB
I did see that but I don't understand how to use it. It essentially hands you a chunk of code and doesn't tell you how to use it

I have also been looking online and many are saying to use ADO, where you would use excel as opposed to a text file. I have been screwing around with this with no success =/.
Here's the article's code with the sub renamed (read makes more sense than dump) and an example to call it, and also a comment in the code. If you actually test the code with a file, it will be more apparent what's going on.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command1_Click()
  2.     ReadFile_V01 ("c:\test.txt")
  3. End Sub
  4.  
  5.  
  6. Public Sub ReadFile_V01(ByVal FileName As String)
  7.   Dim FileNo As Long
  8.   Dim LineNo As Long
  9.   Dim LineText As String
  10.  
  11.   FileNo = FreeFile ' Get next available file number.
  12.  
  13.   Open FileName For Input Access Read Shared As #FileNo
  14.   Do Until EOF(FileNo) ' Repeat until end of file...
  15.     Line Input #FileNo, LineText ' Read a line from the file.
  16.  
  17.  
  18.     'put your code here to deal with the current line of text
  19.     LineNo = LineNo + 1
  20.     Debug.Print Format(LineNo, "00000"); ": "; LineText
  21.  
  22.  
  23.  
  24.     DoEvents ' Allow Windows to handle other tasks.
  25.   Loop
  26.   Close #FileNo
  27. End Sub
  28.  
If you want the password file hosted on a website you can use something like this to download the file:

Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2. Private Sub Command1_Click()
  3.     Dim sHTML
  4.     sHTML = RequestText("http://news.google.com/")
  5.  
  6.     msgbox sHTML
  7.  
  8. End Sub
  9.  
  10. Private Function RequestText(sURL, Optional sMethod = "POST")
  11.     'You may have caching issues using GET
  12.     Dim XMLHTTP
  13.     Set XMLHTTP = CreateObject("microsoft.XMLHTTP")
  14.     sMethod = UCase(sMethod)
  15.     XMLHTTP.Open sMethod, sURL, False
  16.     XMLHTTP.send (Null) '"x=x"
  17.     RequestText = XMLHTTP.responseText
  18.     Set XMLHTTP = Nothing
  19. End Function
Jul 2 '07 #4
Killer42
8,435 Expert 8TB
I did see that but I don't understand how to use it. It essentially hands you a chunk of code and doesn't tell you how to use it

I have also been looking online and many are saying to use ADO, where you would use excel as opposed to a text file. I have been screwing around with this with no success =/.
Hm... ADO and Excel... interesting. I haven't seen it done, but that doesn't prove anything I suppose. I guess both Excel and Access have the advantage of supporting some security measures.

As for the samples, yes they really are just code snippets for people to play with. We don't have anything much in the way of tutorials as yet. There are heaps of VB tutorials available on the web, though. However, let's assume you had a text file with a bunch of user IDs, each one followed on the next line by an encrypted password. Here's a sample I threw together which will prompt you for the name of the file then invoke a little "black box" function to return an array of user IDs and encrypted passwords from it.

This is the complete code module for the function...
Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2.  
  3. Public Type UserStuff
  4.   ID As String
  5.   Psw As String
  6. End Type
  7.  
  8. Public Function GetUserDetailsFromFile(ByVal FileName As String) As UserStuff()
  9.   Dim FileNo As Long
  10.   'Dim LineNo As Long
  11.   Dim LineText As String
  12.   Dim TempUser() As UserStuff
  13.   Dim UserNo As Long
  14.   'Dim TempPsw() As String
  15.  
  16.   FileNo = FreeFile ' Get next available file number.
  17.  
  18.   Open FileName For Input Access Read Shared As #FileNo
  19.   Do Until EOF(FileNo) ' Repeat until end of file...
  20.     UserNo = UserNo + 1
  21.     ReDim Preserve TempUser(1 To UserNo)
  22.     Line Input #FileNo, TempUser(UserNo).ID
  23.     Line Input #FileNo, TempUser(UserNo).Psw
  24.     DoEvents ' Allow Windows to handle other tasks.
  25.   Loop
  26.   Close #FileNo
  27.   GetUserDetailsFromFile = TempUser
  28. End Function
And here's the code in my sample form to test it out...
Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2. Dim MyUserDetails() As UserStuff
  3.  
  4. Private Sub Form_DblClick()
  5.   MyUserDetails = GetUserDetailsFromFile(InputBox("Enter name (including path) of file with users"))
  6.   Dim I As Long
  7.   For I = LBound(MyUserDetails) To UBound(MyUserDetails)
  8.     With MyUserDetails(I)
  9.       Debug.Print "UserID:"; .ID, "Psw:"; .Psw
  10.     End With
  11.   Next
  12. End Sub
Just run it, double-click the form and away you go. It just prints the results to the immediate window.

My sample file was just a text file I created in Notepad, containing these stupid values...
User01
%JFK ASEF:F$$W
User02
45v-98n3pytp4
User03
$%Y$%$K%JFK$$W
Jul 2 '07 #5
ldpfrog
16
Okay, thank you all alot for your help. This was the code that I came up with. I Created an array UInfo(999, 2). The X portion of this array is the maximum amount of usernames and passwords I could set, I could increase the amount but I doubt I'll have over 1000 users using this program. The Y portion is set up so if Y=1 then you are looking at a username, and if Y=2 then it is the password for the corresponding username.

In order for this to work, just create a multiline Textbox and a Command button, with the default VB6 names. I would be happy to explain to anybody who needs it because this is a very simple solution to having multiple usernames and passwords to your program without editing the actual code.


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
  2.  
  3. Private Sub Command1_Click()
  4.  
  5. nFileNum = FreeFile
  6.  
  7.  
  8. Open "C:\Documents and Settings\Matt\My Documents\testing.txt" For Input As nFileNum
  9. lLineCount = 1
  10.  
  11. NumLine = 0
  12. LCount = 1
  13. UnPw = 0
  14. Do While Not EOF(nFileNum)
  15.    Line Input #nFileNum, sText
  16.    LCount = LCount + 1
  17.    If LCount Mod 2 <> 0 Then UnPw = 2
  18.    If LCount Mod 2 = 0 Then
  19.    NumLine = NumLine + 1
  20.    UnPw = 1
  21.    End If
  22.   UInfo(NumLine, UnPw) = sText
  23.  
  24. Loop
  25. UInfo(0, 1) = "UN"
  26. UInfo(0, 2) = "PW"
  27. For x = 0 To LCount
  28. For y = 1 To 2
  29. Text1.Text = Text1 & UInfo(x, y) + " "
  30. Next y
  31. Text1.Text = Text1 & vbCrLf
  32. Next x
  33.  
  34. Close nFileNum
  35.  
  36. End Sub
Jul 8 '07 #6
Killer42
8,435 Expert 8TB
Glad to see you got it working.

Just one piece of general advice I would like to pass on. When you have two mutually exclusive possbilities (such as in lines 17-18 of your code) you should normally code it with an Else clause, as it makes the intention much more obvious. For instance...
Expand|Select|Wrap|Line Numbers
  1. If LCount Mod 2 <> 0 Then
  2.   UnPw = 2
  3. Else
  4.   NumLine = NumLine + 1
  5.   UnPw = 1
  6. End If
Jul 9 '07 #7
ldpfrog
16
I know but I learned programming in TrueBasic and am not used to using 0 in arrays so I was afraid it would screw things up (which it did anyway). But thank you!
Jul 9 '07 #8
Killer42
8,435 Expert 8TB
I know but I learned programming in TrueBasic and am not used to using 0 in arrays so I was afraid it would screw things up (which it did anyway). But thank you!
I never use entry 0 in an array either. I hate zero-based arrays - they go completely against the way humans think, and try to force them to think like computers. They should be banned.

All I was talking about in this case is the structure of the IF tests. You are doing the equivalent of...
Expand|Select|Wrap|Line Numbers
  1. IF Condition Then
  2.   ' Blah blah
  3. End If
  4. If Not Condition Then
  5.   ' Blah blah
  6. End If
In such a case, it's usually simpler to read if you code it as
Expand|Select|Wrap|Line Numbers
  1. IF condition Then
  2.   ' Blah blah
  3. Else
  4.   ' Blah blah
  5. End If
This is largely a personal choice, of course.
Jul 9 '07 #9
ldpfrog
16
Understood, thank you! Check out my other post about reading the file from the internet?
Jul 9 '07 #10

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

Similar topics

3
by: Miranda johnsen | last post by:
Hello, I need some help with passing a value from my login authorization page. The authorization is done with the code below (it works), but I need the 'uName' value passed on when the...
20
by: ishmael4 | last post by:
hello everyone! i have a problem with reading from binary file. i was googling and searching, but i just cant understand, why isnt this code working. i could use any help. here's the source code:...
1
by: Tom Jones | last post by:
Hi, I am using the HttpWebRequest and HttpWebResponse classes to pull information from a web server on the internet. I have an account on one of the webservers that I need to log into...
2
by: dylanhughes | last post by:
I'm looking for an example of a login system that has multiple fields (2 to be exact) + password. e.g username, company name and password, the user, company and password are checked against a mysql...
19
by: klenwell | last post by:
Another request for comments here. I'd like to accomplish something like the scheme outlined at this page here: http://tinyurl.com/3dtcdr In a nutshell, the form uses javascript to hash...
10
by: yasmine | last post by:
Hi friends, I'm writing a login.php script. I stored the password in mysql db as encrypted format using md5. (It's in registration.php and it works well). There is a no problem in registering...
3
by: DotNetNewbie | last post by:
Hi, I have a website that I need to have 2 login pages for, is this possible without creating another virtual web application and having 2 web.config files? My website has a forum and a...
4
by: adam.waterfield | last post by:
I am just wondering if anyone here can help with a problem that we have here. We have a PHP based website/application that has a user login that is connected to our AD setup. This works fine....
1
yawar
by: yawar | last post by:
Hi, I am a newbie in System.Net programming though I have worked on mshtml but I want to do things more perfectly and with speed. I have created one software that login to gmail using...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...

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.