If...then statements question

daveofgv

Well-known member
Joined
Sep 17, 2008
Messages
218
Location
Dallas, TX
Programming Experience
1-3
A very quick question that I have been having trouble finding.......

I need to have multiple users on a program and each one had there own login username and password.

I was thinking about using my.settings for the username/password such as "user1username, user1password, user2username, etc.....

How would my code look???

Right now, for one user I have

VB.NET:
Dim Response As Integer
If usernameTextBox1.Text = My.Settings.username1 AndAlso_
passwordTextBox2.Text.GetHashCode() = My.Settings.PasswordHashCode_ Then

Response = MessageBox.Show("You are now logged in. Welcome Back!", "My Program", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1)If Response = vbOK ThenCopyrightScreen.Show()Me.Close() End IfElseMessageBox.Show("Wrong username or password")End If
If I were to have several users would I put

VB.NET:
 Dim Response As IntegerIf usernameTextBox1.Text = My.Settings.username1 AndAlso usernameTextBox1.Text = My.Settings.username2 AndAlso usernameTextBox1.Text = My.Settings.username3 AndAlso usernameTextBox1.Text = My.Settings.username4 AndAlso passwordTextBox2.Text.GetHashCode() = My.Settings.PasswordHashCode ThenResponse = MessageBox.Show("You are now logged in. Welcome Back!", "My Program", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1)If Response = vbOK ThenCopyrightScreen.Show()Me.Close() End IfElseMessageBox.Show("Wrong username or password")

End If
Thanks

daveofgv
 
You can't add settings at run time. You'd have to use StringCollections to store the user credentials. Also, the data will be stored under the current Windows user profile. If a different user logs into Windows and runs your app then all your user credentials will be inaccessible.

A database table is a far more natural structure to store this sort of data in, plus you can setup security on the database to protect the data if need be. That may bot be necessary if this is just a learning project but it's not a bad idea to familiarise yourself with databases from the get-go because they are integral to the vast majority of applications these days.
 
Back
Top