• Log in or sign up for an account here: https://www.sythe.org/login

[TUT] C# How to add a Basic Password to Programs

Fallen Soul

Apprentice
Joined
Mar 11, 2007
Sythe Gold
0
Messages
746
Location
USA
Well in this tutorial I will teach you how to use an "if statement" to make a very very basic password for your programs.

To start open up your Visual studio and Click Create New Project > Windows form application (Name it what ever you want)
openitupdb8.png


Go to your toolbox and add a button, and a textbox to your form.
buttonntextji6.png


Double click on your button and it should open up and look like this.
looklikethisbi2.png


Now add this code...

Code:
if (textBox1.Text == ("Jaghax"))
{
 MessageBox.Show("Correct!");
}
This is simply telling your program that if the word "Jaghax" is entered into your textbox , then it should show you the Messagebox.

So far this is what you should have and what it should look like.
codeaddedpw4.png



Push the start button at the top, or go to Debug > Start debugging
starttw0.png


Something like this should popup depending on where you put your buttons and if you named them.

thereim9.png

Notice, if you put anything else into the textbox it does nothing. That's cause we haven't told it what to do if something else is put there.

Now we need to tell our program what to do if some one gets the password wrong.


Now we need to tell our program to to do if something else is put in the textbox
Add this right below the last "}" in the "if statement"

Code:
else
{
 Application.Exit();
}
This is telling your program to close itself if anything other word is in the textbox other then your set password

It should now look like this
newlineci5.png


Now open your project again and type in a different word, other then "Jaghax". If you did it right it should instantly close.

This is the end of my tutorial, thank you for reading and if you have any questions or advice please feel free to post it. (I made this myself and I posted it on a different site but felt that it should be released here as well)​
 
duelarena.gg
Back
Top