Login function

Started by
4 comments, last by Ilici 19 years, 6 months ago
I'm programming in Visual basic. It's no problem making a Login function, but my problem is to hav a easy way to add users and their passwords... Here's the code block: Dim Usr, Pass Usr = "alek" Pass = "psw" If txtUserName = Usr If txtPassword = Pass Then LoginSucceeded = True Load Form1 Form1.Show Unload frmLogin Else MsgBox "Wrong password, try again!", , "Login" txtUserName.SetFocus SendKeys "{Home}+{End}" End If Anyway to add more users without many Else If test?? Thankz for any replies...
Advertisement
I don´t remember Visual Basic´s syntax that well so here´s just an explanation:

Put users and passwords in to the arrays and then loop through them.
An easy way would be to have an array of usernames and passwords. Then you can just use a loop to cycle through each entry in the array to check whether it matched the entered username and password.

I think that the way rpofessional software does it (although im not sure) is to have a database of usernames and passwords (which is probably goin to end up in an array anyway once its loaded) to store the passwords and load it at run time.

I think the array would be your best bet to try out for now though:)

EDIT: beaten to it lol
Quote:Original post by BosskIn Soviet Russia, you STFU WITH THOSE LAME JOKES!
Quote:Original post by grekster
I think that the way rpofessional software does it (although im not sure) is to have a database of usernames and passwords (which is probably goin to end up in an array anyway once its loaded) to store the passwords and load it at run time.


It's actually not necessary for the application to store the list at all. You can just tell the database 'send me the password for user X' and compare it (with appropriate security precautions blah blah). One advantage is that no special handling is needed to allow users to be added or passwords changed while the program is running.

There are ways of doing all this in VB but it's extreme overkill for a simple app.
thankz for the replies...
One question though. I'm a noob, this is actually my first app.
What exactly do you mean by an array..? I'm not that good at looping yet.
Quote:Original post by Dj_aLek
What exactly do you mean by an array..? I'm not that good at looping yet.


lol, looping takes some practice to get good at :P

An array is a continuous block of memory which stores some variables of the same type under a single name. To reference each variable you use an index:

Dim a(100) as Integer

will create the array "a" which contains 100 integers. These integers' indices will be from 0 to 99.

a(i) will reference the i_th integer in a
(if this 0-99 indice numbering is confusing you can use
"Option Base 1" to make them be from 1 to 100).

Now to parse the array you use a loop:

For i = 0 to 99
//do stuff with a(i)
Next

This topic is closed to new replies.

Advertisement