This being the first code sample I’m posting here, I thought I’d do the simplest thing I know to do.
A lot of websites and applications require authentication before allowing the user to access certain features. Most of these websites/applications will check values entered by the user against existing records in a database of some kind, but because we’re KISSING (keeping it simple stupid), we’re going to use a hard-coded password.
This kind of security is by no means the best to use, but it should work fine until we get to using database records for authentication.
What we’re going to do is define a password in our click event handler and check the user-entered value against that.
Here we go!!!
Sub btnSignIn_Click(ByVal Sender As Object, ByVal e As System.EventArgs) Handles btnSignIn_Click
If txtPassword.Text = “somePasswordHere” Then
‘ For windows forms, you could use the following:
‘ frmUserName.Visible = True
‘ For Windows forms, display a message box:
‘ MsgBox(“Incorrect Password.”)
lblError.Text = “Incorrect Password.”
All the login form consists of is a label indicating the password field, a label (not visible initially) and the button.
There couldn’t be anything simpler! And the best part is that we don’t even need to write any exception handling code because no matter what is entered into the textbox, it’ll still either redirect, or notify the user of an invalid input via the label/message box.
So that’s it from me, let me know if this helped you with anything you’ve been trying to do. Keep watching out for more code samples – they’re going to get more impressive as time goes by.
Thanks for your time! Enjoy your coding!