""
All times are GMT -5. The time now is 10:18 AM.  

Go Back   Delta Hackers > [::General Programming::] > C#

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 03-04-2010
Kryptech's Avatar
Kryptech Kryptech is offline

 
Join Date: May 2007
Location: Right Behind You
Posts: 2,978
Downloads: 44
Uploads: 13
Rep Power: 24052
Kryptech has a reputation beyond reputeKryptech has a reputation beyond reputeKryptech has a reputation beyond reputeKryptech has a reputation beyond reputeKryptech has a reputation beyond reputeKryptech has a reputation beyond reputeKryptech has a reputation beyond reputeKryptech has a reputation beyond reputeKryptech has a reputation beyond repute
Kryptech has a reputation beyond reputeKryptech has a reputation beyond reputeKryptech has a reputation beyond reputeKryptech has a reputation beyond reputeKryptech has a reputation beyond reputeKryptech has a reputation beyond reputeKryptech has a reputation beyond reputeKryptech has a reputation beyond reputeKryptech has a reputation beyond reputeKryptech has a reputation beyond reputeKryptech has a reputation beyond reputeKryptech has a reputation beyond reputeKryptech has a reputation beyond reputeKryptech has a reputation beyond reputeKryptech has a reputation beyond repute

Awards Showcase
Iteration Award 2000th Post Tutorial Maker Problem Solver Most Valued Coder Most Improved Coder Innovation Clean Coder Advanced Coder Active Contributor 
Total Awards: 19

Default Password Protecting a Form

This is a short tutorial on password protecting your trainer. I will assume you have a basic knowlede of C# for this tutorial, if not, please read this tutorial first http://www.delta-h.net/forum/showthread.php?t=8729.

To start off, make a new windows form project. In the main form properties set the control Box option to false. This disables the close button on the top border. We do this because if you hit this close button on form 2 the applicatin will not close properly.

Click the image to open in full size.

Next we are going to add a text Box. The only properties you need to set up on this is to set the password char. I used "*" but you can use whatever you want.

I added a tool tip to the text Box control to display when you hover over it with mouse. This is purely optional, but it's so easy to do I figured its worth the time explaining. drag the tool tip control to the text Box. It should show up at bottom of form window. Set the few options to your preference. To make it work simply add the following line to your Form1 Load function so it looks like this:
PHP Code:
private void Form1_Load(object senderEventArgs e)
{
toolTip1.SetToolTip(textBox1"Enter the password");

Parameter 1 is the name of the control you want the tool tip to display over, and obviously param 2 is the text you want displayed.

The last thing we need to add to form 1 is the buttons. We need a submit button and an exit button. Go ahead and do that now. Once that is done we are going to make our second form. This will be the actual trainer, but for the sake of simplicity I am just making a simple form with a close button.

Go to Project->add Windows Form Select Windows Form and hit ADD.
Click the image to open in full size.

Set this form up like the first change the properties so that there is no close buttom on the border. Now add an exit button to this form.

Go back to form 1 and double click the submit button. This will take us to the button click function. Add the following code to that for. At the top after publicpartialclassForm1 : Form
{
add the following line:
Form2 mainForm = newForm2();
This sets up our form object to use.

Then in the button function add the following code so it looks like this.

PHP Code:
private void button1_Click(object senderEventArgs e)
{
if(
textBox1.Text == "password"//This compares the entered text to what is in the quotes.
{
//This makes our second form show
mainForm.Show();
//This makes the first form close without closing the whole program
this.Dispose(false);
this.Close();
}else 
MessageBox.Show("Wrong password"); 

All thats left to do now is make the exit buttons work. So, on each form, double click the exit button and add the following line to the button click functions:

Application.Exit();

This will close the application properly.

Now compile and run. That is all there is to it. This is what you should have if done correctly:
Click the image to open in full size.

Now just make Form2 your trainer and you dont have to worry about unwanted people using your trainer.
__________________
Click the image to open in full size.

Reply With Quote
  #2  
Old 03-04-2010
Iteration's Avatar
Iteration Iteration is offline
The Enforcer

 
Join Date: Oct 2007
Location: US - GA/FL/SC/MN USMC.
Posts: 2,719
Downloads: 118
Uploads: 51
Rep Power: 7160
Iteration has a reputation beyond reputeIteration has a reputation beyond reputeIteration has a reputation beyond reputeIteration has a reputation beyond reputeIteration has a reputation beyond reputeIteration has a reputation beyond reputeIteration has a reputation beyond reputeIteration has a reputation beyond reputeIteration has a reputation beyond repute
Iteration has a reputation beyond reputeIteration has a reputation beyond reputeIteration has a reputation beyond reputeIteration has a reputation beyond reputeIteration has a reputation beyond reputeIteration has a reputation beyond reputeIteration has a reputation beyond reputeIteration has a reputation beyond reputeIteration has a reputation beyond reputeIteration has a reputation beyond reputeIteration has a reputation beyond reputeIteration has a reputation beyond reputeIteration has a reputation beyond reputeIteration has a reputation beyond reputeIteration has a reputation beyond repute

Awards Showcase
Iteration Award 2000th Post SRV's Man Award Tutorial Maker Problem Solver Most Improved Coder Most Valued Coder Innovation Nice GUI Clean Coder 
Total Awards: 19

Default

Good tutorial. Small suggestion though, don't add an message box stating the password is wrong. That way makes it harder to trace back to the compare.
__________________

Click the image to open in full size.
Click the image to open in full size.
Click the image to open in full size.
Click the image to open in full size.
Click the image to open in full size.
Click the image to open in full size.

When in Doubt... Empty the Magazine.

Ghost's with empty souls leave .308 holes.
Death smile's at everyone, Marines smile back.

AS YOU WALK THROUGH THE VALLEY OF THE SHADOW OF DEATH, YOU WILL FEAR ALL EVIL, BECAUSE I AM THE SHADOW OF DEATH AND THIS IS MY FUCKING VALLEY!
Reply With Quote
  #3  
Old 03-04-2010
KN0WF34R's Avatar
KN0WF34R KN0WF34R is offline
Moderator

 
Join Date: Aug 2008
Location: Under Ghoster's Trailer
Posts: 708
Downloads: 27
Uploads: 3
Rep Power: 4028
KN0WF34R has a reputation beyond reputeKN0WF34R has a reputation beyond reputeKN0WF34R has a reputation beyond reputeKN0WF34R has a reputation beyond reputeKN0WF34R has a reputation beyond reputeKN0WF34R has a reputation beyond reputeKN0WF34R has a reputation beyond reputeKN0WF34R has a reputation beyond reputeKN0WF34R has a reputation beyond repute
KN0WF34R has a reputation beyond reputeKN0WF34R has a reputation beyond reputeKN0WF34R has a reputation beyond reputeKN0WF34R has a reputation beyond reputeKN0WF34R has a reputation beyond reputeKN0WF34R has a reputation beyond reputeKN0WF34R has a reputation beyond reputeKN0WF34R has a reputation beyond reputeKN0WF34R has a reputation beyond reputeKN0WF34R has a reputation beyond reputeKN0WF34R has a reputation beyond reputeKN0WF34R has a reputation beyond reputeKN0WF34R has a reputation beyond reputeKN0WF34R has a reputation beyond reputeKN0WF34R has a reputation beyond repute

Awards Showcase
Tutorial Maker Most Improved Coder Clean Coder Advanced Coder Active Contributor Iteration Award 1 Year Vetern $50 Donator $20 Donator $10 Donator 
Total Awards: 11

Default

Quote:
Originally Posted by Iteration View Post
Good tutorial. Small suggestion though, don't add an message box stating the password is wrong. That way makes it harder to trace back to the compare.
Hmmm, I need to build and run this in Olly before I go sticking my foot in my mouth with an unresearched reply.
__________________
Quote:
Originally Posted by fef View Post
yea i wanna like go to a warez site and get c++
but i dont want a virus.. =/
Click the image to open in full size.
Click the image to open in full size.
Click the image to open in full size.
Reply With Quote
  #4  
Old 03-04-2010
Bountyhuntr Bountyhuntr is offline
Banned
 
Join Date: Feb 2010
Posts: 3
Downloads: 0
Uploads: 0
Rep Power: 0
Bountyhuntr is an unknown quantity at this point
Default

Surely that password which is stored in the exe is easily obtainable as it's a string, you could just open it in notepad and see it plain as day.
Reply With Quote
  #5  
Old 03-05-2010
Kryptech's Avatar
Kryptech Kryptech is offline

 
Join Date: May 2007
Location: Right Behind You
Posts: 2,978
Downloads: 44
Uploads: 13
Rep Power: 24052
Kryptech has a reputation beyond reputeKryptech has a reputation beyond reputeKryptech has a reputation beyond reputeKryptech has a reputation beyond reputeKryptech has a reputation beyond reputeKryptech has a reputation beyond reputeKryptech has a reputation beyond reputeKryptech has a reputation beyond reputeKryptech has a reputation beyond repute
Kryptech has a reputation beyond reputeKryptech has a reputation beyond reputeKryptech has a reputation beyond reputeKryptech has a reputation beyond reputeKryptech has a reputation beyond reputeKryptech has a reputation beyond reputeKryptech has a reputation beyond reputeKryptech has a reputation beyond reputeKryptech has a reputation beyond reputeKryptech has a reputation beyond reputeKryptech has a reputation beyond reputeKryptech has a reputation beyond reputeKryptech has a reputation beyond reputeKryptech has a reputation beyond reputeKryptech has a reputation beyond repute

Awards Showcase
Iteration Award 2000th Post Tutorial Maker Problem Solver Most Valued Coder Most Improved Coder Innovation Clean Coder Advanced Coder Active Contributor 
Total Awards: 19

Default

Ofcourse this is not secure against reversing. That is a whole other tutorial. Just trying to give basic explanations of things in C#. From what I can tell it seems to have all the benefits of both VB and C++. I have not tried anything serious with it yet, I am just learning it myself. Pretty much all the rules and techniques for security are the same for a C# app. Don't store the password in a simple variable or as a string in memory. Exit silently if wrong password. Compress and encrypt final file, etc...
__________________
Click the image to open in full size.

Reply With Quote
  #6  
Old 03-14-2010
dremation's Avatar
dremation dremation is offline
Member
 
Join Date: Nov 2007
Location: Missouri
Posts: 67
Downloads: 9
Uploads: 2
Rep Power: 70
dremation is a jewel in the rough
dremation is a jewel in the roughdremation is a jewel in the roughdremation is a jewel in the roughdremation is a jewel in the rough
Send a message via MSN to dremation Send a message via Yahoo to dremation Send a message via Skype™ to dremation
Default

You could store a small text file on a remote server and read that file. I'll explain and show an example. This way you can change the username/password as you see fit.

http://mycoolsite.com/mydata.txt

In this text file add the line:
Code:
username:password
(replace with your username/password, and I'd go ahead and hash that password)

In C# create a new application or add a WinForm to an existing application. (frmLogin)

For this example you'll need to use to Namespaces. System.Net, System.Web
Code:
using System.Net;
using System.Web;
using System.Security.Cryptography; //(if you want to hash your password, witch I suggest)
================================

On frmLogin add 2 textbox's and a button. Cleverly name them txtUser, txtPass and btnLogin.

On the btnLogin click event you want to add the following.

Code:
            string dataFile="http://yourcoolsite.com/mydata.txt
            WebClient wc = new WebClient();
            UTF8Encoding utf8 = new UTF8Encoding();
            string requestHtml = "";
            requestHtml = utf8.GetString(wc.DownloadData(dataFile));
           
           string[] loginData = requestHtml.Split(':');
           
            if(loginData[0] != txtUser.Text || loginData[1] != md5(txtPass.Text))
             {
                MessageBox.Show("Invalid Credentials!");
             } 
            else 
            {
                //do your approved work here
            }
If you've opted to use the md5 of the password then include this function as well.

Code:
private string md5(string password)
        {
            System.Security.Cryptography.MD5CryptoServiceProvider x = new System.Security.Cryptography.MD5CryptoServiceProvider();
            byte[] data = System.Text.Encoding.ASCII.GetBytes(password);
            data = x.ComputeHash(data);
            string ret = "";
            for (int i = 0; i < data.Length; i++)
                ret += data[i].ToString("x2").ToLower();
            return ret;
        }
That should be it. If you want added protection for the mydata.txt throw an .htaccess file in the directory denying access.
Reply With Quote
  #7  
Old 04-29-2010
Kraken's Avatar
Kraken Kraken is offline
Member
 
Join Date: Apr 2010
Location: Pennsylvania
Posts: 67
Downloads: 5
Uploads: 2
Rep Power: 699
Kraken has a reputation beyond reputeKraken has a reputation beyond reputeKraken has a reputation beyond repute
Kraken has a reputation beyond reputeKraken has a reputation beyond reputeKraken has a reputation beyond reputeKraken has a reputation beyond reputeKraken has a reputation beyond reputeKraken has a reputation beyond reputeKraken has a reputation beyond reputeKraken has a reputation beyond reputeKraken has a reputation beyond reputeKraken has a reputation beyond reputeKraken has a reputation beyond reputeKraken has a reputation beyond repute
Default

You could also use DES encryption in the cryptology namespace, or obfuscate your program so it can't be easily decrypted in notepad.

BTW, this is my first post
__________________
Click the image to open in full size.
Reply With Quote
  #8  
Old 07-23-2010
treax treax is offline
Recruit
 
Join Date: Jun 2010
Posts: 1
Downloads: 0
Uploads: 0
Rep Power: 0
treax is an unknown quantity at this point
Default

Thanks. Very good tutorial, i tried and it worked
Reply With Quote
Reply

Tags
form, password, protecting

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 10:18 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.