Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to implement functionality of registration key to use software what I have done is as follows:-
I tried on concept of storing key in registry and comparing the same on application start


C#
private void Form1_Load(object sender, EventArgs e)//Main Form for application
        {
//Disable Application Menus
             if(CheckRegKey()==true)
             {
             //Enable Application Menus
             }
             else
             {
             MessageBox.Show("Please register to use the software.!!");
               Application.Exit();
               }

        }

private bool CheckRegKey()
        {
           bool data=false;
           
           int key=(int)Microsoft.Win32.Registry.GetValue("\\HKEY_CURRENT_USER\\Software\\Mysoft", "RegCode", 0);

        if(key==123456)
         {
         data=true;
          }
          return data;
        }






The value of the key RegCode is set to 0 by installer when it installs so user is unable to use software unless he:-
1)Enters a key through Register Form which writes the value of key RegCode in registry after checking with key chosen for program i.e 123456


C#
//Registration Form
private void btnRegister_Click(object sender, EventArgs e)
if(Convert.ToInt32(txtRegCode.txt)==123456)
{
Microsoft.Win32.Registry.SetValue("\\HKEY_CURRENT_USER\\Software\\Mysoft", "RegCode",  Convert.ToInt32(txtRegCode.txt));
MessageBox.Show("Registration Successful!!");
}
else
{
MessageBox.Show("Registration Failed !!");
}
}



However this seems working is there a better way to do this as:-

1)The key is hardcoded in program to use diffrent keys everytime the application needs to be compiled with new key and also its setup needs to be created again

2)Key is visble in registry when we search key Mysoft
Posted

1 solution

This is indeed a good start.

If you have a serious business need on a commercial software it is probably simpler to buy an off the shelf product.

However if you're coding for fun, this a good concept to work on.

The main flaw here is that your software use the same registration key for everybody.
If someone has the key, he could just divulge it on a forum and then everyone has it.

I believe your first task would be to make the key different for two every machine or user.

This way there are no need to hide the key as it can't be copied to another machine anyway.

What I would do is use 2 registry keys:

UserId: pascal324234@gmail.com
RegCode: ASDFSDFSDFSDF

Then you can check the key

C#
string registeredName; // read from registry
string actualRegistrationCode; // read from registry
string secretSeed = ":MantuSingh438";
string expectedRegistrationCode = (registeredName + secretSeed).GetHashCode().ToString("x");

if(expectedRegistrationCode == actualRegistrationCode)
{
         data=true;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900