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
9 1355
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.
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 =/.
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. -
Private Sub Command1_Click()
-
ReadFile_V01 ("c:\test.txt")
-
End Sub
-
-
-
Public Sub ReadFile_V01(ByVal FileName As String)
-
Dim FileNo As Long
-
Dim LineNo As Long
-
Dim LineText As String
-
-
FileNo = FreeFile ' Get next available file number.
-
-
Open FileName For Input Access Read Shared As #FileNo
-
Do Until EOF(FileNo) ' Repeat until end of file...
-
Line Input #FileNo, LineText ' Read a line from the file.
-
-
-
'put your code here to deal with the current line of text
-
LineNo = LineNo + 1
-
Debug.Print Format(LineNo, "00000"); ": "; LineText
-
-
-
-
DoEvents ' Allow Windows to handle other tasks.
-
Loop
-
Close #FileNo
-
End Sub
-
If you want the password file hosted on a website you can use something like this to download the file: - Option Explicit
-
Private Sub Command1_Click()
-
Dim sHTML
-
sHTML = RequestText("http://news.google.com/")
-
-
msgbox sHTML
-
-
End Sub
-
-
Private Function RequestText(sURL, Optional sMethod = "POST")
-
'You may have caching issues using GET
-
Dim XMLHTTP
-
Set XMLHTTP = CreateObject("microsoft.XMLHTTP")
-
sMethod = UCase(sMethod)
-
XMLHTTP.Open sMethod, sURL, False
-
XMLHTTP.send (Null) '"x=x"
-
RequestText = XMLHTTP.responseText
-
Set XMLHTTP = Nothing
-
End Function
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... - Option Explicit
-
-
Public Type UserStuff
-
ID As String
-
Psw As String
-
End Type
-
-
Public Function GetUserDetailsFromFile(ByVal FileName As String) As UserStuff()
-
Dim FileNo As Long
-
'Dim LineNo As Long
-
Dim LineText As String
-
Dim TempUser() As UserStuff
-
Dim UserNo As Long
-
'Dim TempPsw() As String
-
-
FileNo = FreeFile ' Get next available file number.
-
-
Open FileName For Input Access Read Shared As #FileNo
-
Do Until EOF(FileNo) ' Repeat until end of file...
-
UserNo = UserNo + 1
-
ReDim Preserve TempUser(1 To UserNo)
-
Line Input #FileNo, TempUser(UserNo).ID
-
Line Input #FileNo, TempUser(UserNo).Psw
-
DoEvents ' Allow Windows to handle other tasks.
-
Loop
-
Close #FileNo
-
GetUserDetailsFromFile = TempUser
-
End Function
And here's the code in my sample form to test it out... - Option Explicit
-
Dim MyUserDetails() As UserStuff
-
-
Private Sub Form_DblClick()
-
MyUserDetails = GetUserDetailsFromFile(InputBox("Enter name (including path) of file with users"))
-
Dim I As Long
-
For I = LBound(MyUserDetails) To UBound(MyUserDetails)
-
With MyUserDetails(I)
-
Debug.Print "UserID:"; .ID, "Psw:"; .Psw
-
End With
-
Next
-
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
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. - Dim nFileNum As Integer, UInfo(999, 2) As String, sNextLine As String, lLineCount As Long, NumLine As Integer, LCount As Integer, UnPw As Integer
-
-
Private Sub Command1_Click()
-
-
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
-
UInfo(0, 1) = "UN"
-
UInfo(0, 2) = "PW"
-
For x = 0 To LCount
-
For y = 1 To 2
-
Text1.Text = Text1 & UInfo(x, y) + " "
-
Next y
-
Text1.Text = Text1 & vbCrLf
-
Next x
-
-
Close nFileNum
-
-
End Sub
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... - If LCount Mod 2 <> 0 Then
-
UnPw = 2
-
Else
-
NumLine = NumLine + 1
-
UnPw = 1
-
End If
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 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... - IF Condition Then
-
' Blah blah
-
End If
-
If Not Condition Then
-
' Blah blah
-
End If
In such a case, it's usually simpler to read if you code it as - IF condition Then
-
' Blah blah
-
Else
-
' Blah blah
-
End If
This is largely a personal choice, of course.
Understood, thank you! Check out my other post about reading the file from the internet?
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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:...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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....
|
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...
|
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,...
|
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$) {
}
...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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,...
| |