(adsbygoogle = window.adsbygoogle || []).push({});
*** THIS WILL WORK EVEN IF THE USER IS NOT CONNECTED TO THE INTERNET ***
Introduction:
Hey NGU, this is the third tutorial in the VB.net programming series. Sorry it has been a week, just had a lot of stuff going on
. Of course, I have checked and am almost positive there is no other threads on how to do this.
Tutorial: #3 - Password Protected Forms
Required Materials:
~ VB 2008 or 2010
- 2 textbox's
- 3 forms
- 2 buttons
Features:
We are going to make a main form, and a second form that only people that have the password can access. A third form will be the password field.
Video:
[Coming Soon]
How to do it:
First, you're going to create a new WindowsFormApplication, OR a project that is already a WindowsFormApplication.
You must login or register to view this content.
Now once you have done this, you may customize the form and such. You should see something similar to this on your screen:
You must login or register to view this content.
Now you can customize this form to whatever you want, but I am only showing you how to make the password protection part. It will not matter what your projects final program is. I am just going to add a button in the middle that says "Go to password protected form". It doesn't need to be a button it can be a menu strip item as well (same code).
You must login or register to view this content.
Next we are going to add another form to our application. To do this, we will be using the IDE menu strip at the top. Go to Project -> Add Windows Form.
You must login or register to view this content.
You can leave it as form2.vb as you want, its just for the menu tree and will not be seen by the end user. Now we have form 2, you can add your premium content to this page that you want password protected. I'm gonna leave that up to you guys, because it obviously depends on what you're making. Now we are going to repeat this process for form3. Form 3 is the form that we will be using as our password barrier.
Add 2 textbox's, and 1 button to form3. Put 1 textbox in the middle, the button to the right, left, above, or below the textbox, and the 2nd text box, put it somewhere on the form off to the side (The user won't be seeing this). I am setting the password entry textbox to multiline and making the font bigger. You don't have to do this, but its recommended. I also set the textalign property to center. I also added a label to let the user know that it is password protected. You don't need the label, but once again it is recommended.
You must login or register to view this content.
Now for the second textbox, we are going to set its visible property to FALSE. This is important, as the second textbox will be holding the preset password!
You must login or register to view this content.
Lastly, for the button. We are going to start the coding, and this is the last part of this tutorial. Double click the button to bring it up in the code editor. We are going to use IF and ELSE statements, as its a fast and easy way.
You must login or register to view this content.
Here is teh code:
If TextBox1.Text = TextBox2.Text Then
Form2.Show()
MsgBox("The password you entered has been verified and is valid. Click OK to proceed.", MsgBoxStyle.Information)
Else
MsgBox("The password you entered is not valid. Click OK to try again.", MsgBoxStyle.Critical)
End If
Now all we need to do is go back to form1, and double click that button. Just put the following in the button bracket of code:
form3.show
That's it! Now just enter a password in textbox 2's text property, and if the password textbox's text matches it, it will proceed, if it does not, it will give the user an error message. Here is an example of the correct password and incorrect password:
Incorrect
You must login or register to view this content.
Correct
You must login or register to view this content.
ALSO, to make it more professional if you want, you can set the password textbox field to mask the password with asterisk (*). To do this, modify textbox 1's password char property, and set it to anything. The general use is *.
You must login or register to view this content.
Here is a picture of what it looks like in the program:
You must login or register to view this content.
Stay tuned for more and better tutorials