Post: VB.NET Programming Tutorial - PASSWORD PROTECTED FORMS
03-24-2013, 01:50 PM #1
Specter
Pro Memer
(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 Winky Winky. 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 Winky Winky
Last edited by Specter ; 03-24-2013 at 07:11 PM.
03-24-2013, 02:49 PM #2
Sloth
Banned
Originally posted by NGU
*** THIS WILL ONLY 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 Winky Winky. 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 Winky Winky

Nice tutorial but would it not be better to just create a string with the password and then have the button check textbox1 against the string?
It just seems simpler and easier.

Otherwise great tutorial keep it up!
03-24-2013, 02:57 PM #3
Specter
Pro Memer
Originally posted by KronosCloud View Post
Nice tutorial but would it not be better to just create a string with the password and then have the button check textbox1 against the string?
It just seems simpler and easier.

Otherwise great tutorial keep it up!


Actually yes that is an idea too, I think I have done that before and it is actually simpler, but with a textbox its a lot easier for the user to change the password. Thanks for the compliment Smile
03-24-2013, 06:25 PM #4
Pichu
RIP PICHU.
If you want to confuse the person, use MD5>SHA1 on the password and set it as the password wanted.

Then just hash out the inserted password in the same order to get the same results. If anyone looks at the source, they can't see the password right then and there and will have to figure out the password that matches.
03-24-2013, 08:57 PM #5
nay1995
The Master
Originally posted by NGU
*** 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 Winky Winky. 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 Winky Winky


what i do i save a password to a textfile, then use streamReader in my program, then read the text file and see if textbox1 matches the text file text if so the proceed else decline access, doing this way also allow you to update the password when u wish via the program etc and then maybe incorporate a hash to make the password less crack able

---------- Post added at 08:57 PM ---------- Previous post was at 08:55 PM ----------

if u wanted to make an online login system you could also allow users to create accounts, then save their password / usernames etc. to a file on a server of your choice then read files of the server, im getting a little carried away but still...
03-24-2013, 09:36 PM #6
Specter
Pro Memer
Originally posted by nay1995 View Post
what i do i save a password to a textfile, then use streamReader in my program, then read the text file and see if textbox1 matches the text file text if so the proceed else decline access, doing this way also allow you to update the password when u wish via the program etc and then maybe incorporate a hash to make the password less crack able

---------- Post added at 08:57 PM ---------- Previous post was at 08:55 PM ----------

if u wanted to make an online login system you could also allow users to create accounts, then save their password / usernames etc. to a file on a server of your choice then read files of the server, im getting a little carried away but still...


For the first suggestion, an easier way would be to put an XML reader function and read the string from an external XML file (How to do so is in my AUTO UPDATER tutorial (first tutorial)).

For the second suggestion, you could do that but I am basically giving tutorials for the fundamentals of programming in vb.net, not the whole gig :p
03-25-2013, 04:38 PM #7
nay1995
The Master
Originally posted by NGU
For the first suggestion, an easier way would be to put an XML reader function and read the string from an external XML file (How to do so is in my AUTO UPDATER tutorial (first tutorial)).

For the second suggestion, you could do that but I am basically giving tutorials for the fundamentals of programming in vb.net, not the whole gig :p



we all have our own favored methods. Smile
03-26-2013, 11:01 PM #8
Master Ro
I make food
Originally posted by nay1995 View Post
what i do i save a password to a textfile, then use streamReader in my program, then read the text file and see if textbox1 matches the text file text if so the proceed else decline access, doing this way also allow you to update the password when u wish via the program etc and then maybe incorporate a hash to make the password less crack able

---------- Post added at 08:57 PM ---------- Previous post was at 08:55 PM ----------

if u wanted to make an online login system you could also allow users to create accounts, then save their password / usernames etc. to a file on a server of your choice then read files of the server, im getting a little carried away but still...



Or you could use an embedded database :p
03-28-2013, 05:03 PM #9
nay1995
The Master
Originally posted by Master
Or you could use an embedded database :p


if you wanted to make an online login system then yes a database would be necessary but i wouldn't use one for an offline login system.
11-09-2013, 06:00 AM #10
You must login or register to view this content. buyers of tramadol - tramadol medication 100mg

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo