Click here to Skip to main content
Click here to Skip to main content

Keygen for Application

, 5 Oct 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
Application usage topup tool

Introduction

If you want your application to allow the user to use it specific number of times, here is the tool for doing that. This tool generates the key which specifies the number of times the application can be used. The user can get more number of application usage by paying & getting topup keys. Comments are introduced at every level for better understanding of code usage.

About the Tool

The code is written in C# .NET with .NET framework 4. There are two components (both attached with the article) in the tool. One is for vendor side and the other is for customer side. The same algorithm runs on both the sides to generate key. But in customer side, in addition to generation, the matching of generated key with the user input key is done. In this tool, the default number of application usage is 999.

Working

The tool generates a random string, which is unique for each topup, on the customer system. The random string will change on every successful topup. The topup key is generated on vendor system based on the random string generated on the customer system. This topup key can be used to get topup on customer system.

Application Usage

If the customer wants to extend his number of application usage, he/she should mail the system ID (generated random string) to the application vendor along with the payment details.

1.jpg

After verifying the payment details, the vendor should generate the topup key for the user using the system ID given by the customer and send it to the customer.

The customer can use the topup key for one time topup.

1.jpg

Using the Code

  1. Random string generation (on customer system only):
    pkey = RandomString() + RandomInt(); // generation of random string 
    private string RandomString() // gets the first part of random string
            {
              StringBuilder builder = new StringBuilder();
              Random random = new Random();
              char ch;
              for (int i=0; i<8; i++)
              {
                ch = Convert.ToChar(Convert.ToInt32(Math.Floor
    				(26 * random.NextDouble() + 65)));
                builder.Append(ch);
              }
              return builder.ToString();
            }
    
            private string RandomInt() // gets the second part of random string
            {
                int n;
                string ret ="";
                Random r = new Random();
    
                n = r.Next(11111, 99999);
                ret = n.ToString();
    
                return ret;
            }
  2. Topup key generation (on both systems):

    Here GetChar() & GetNum() are the functions used to code the key.

    key = MakeKey();  
    private string MakeKey() // Generating the topup key
            {
                String pkey = keygen();
                char[] key1 = new char[19];
    
                key1[0] = GetChar(pkey[8]);
                key1[1] = GetNum(pkey[4]);
                key1[2] = GetNum(pkey[1]);
                key1[3] = '9';
                key1[4] = '-';
                key1[5] = GetChar(pkey[9]);
                key1[6] = '9';
                key1[7] = GetNum(pkey[2]);
                key1[8] = GetChar(pkey[10]);
                key1[9] = '-';
                key1[10] = GetChar(pkey[12]);
                key1[11] = GetNum(pkey[3]);
                key1[12] = GetNum(pkey[6]);
                key1[13] = '9';
                key1[14] = '-';
                key1[15] = GetChar(pkey[11]);
                key1[16] = GetNum(pkey[0]);
                key1[17] = GetNum(pkey[7]);
                key1[18] = GetNum(pkey[5]);
    
                string skey = "";
                int i;
    
    // 999 application runs by default 
    // To change the default value edit key[3], key[6] & key[13]
    //which denotes 3 digits of runs respectively (max : 999)
    
                    for (i = 0; i < 19; i++)
                        skey += key1[i];
    
                   return skey;
            }
  3. Matching the topup keys and applying the change in application usage number (on customer system only):
    if (textBox1.Text == key && textBox2.Text == keygen())
     {
       ..........
       ..........
    
       // check the source for complete code
       MessageBox.Show("Topup Successful", "Success", 
    		MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
    
    else
     {
      MessageBox.Show("Invalid Topup", "Unsuccess", 
    		MessageBoxButtons.OK, MessageBoxIcon.Warning);
     } 

On some systems, access for the files in the path "Environment.GetFolderPath(Environment.SpecialFolder.System)" are not permitted in IDE.

Install and check the application.

Points of Interest

  • One topup up key can be used only once by the customer.
  • Topup key of one customer system can't be used on other systems.
  • Keys & number of application usage are maintained even when the application is uninstalled/reinstalled.
  • Simple string manipulation involved, no external library required.

History

  • 5th October, 2011: Initial post

License

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

Share

About the Author

Srikanth Anandateertha
Software Developer
India India
No Biography provided

Comments and Discussions

 
GeneralMy vote of 4 Pinmembermahesh07 from Pune12-Mar-12 3:10 
GeneralMy vote of 5 PinmemberWarrick Procter16-Oct-11 15:29 
GeneralMy vote of 5 PinmemberJhon 26-Oct-11 0:01 
GeneralMy vote of 5 Pinmemberthund3rstruck5-Oct-11 14:07 
GeneralMy vote of 3 PinmemberMahmood Rasuli5-Oct-11 11:50 
GeneralRe: My vote of 3 PinmemberSrikanth Anandateertha5-Oct-11 20:07 
GeneralRe: My vote of 3 PinmemberCharles Cox6-Oct-11 18:53 
Every suggestion, when valid, is important. Without suggestions, one can never realize the true potential of their code.
GeneralMy vote of 5 PinmemberSergio Andrés Gutiérrez Rojas5-Oct-11 7:34 
GeneralMy vote of 2 PinmemberWooters5-Oct-11 5:56 
GeneralRe: My vote of 2 PinmemberSrikanth Anandateertha5-Oct-11 6:17 
GeneralRe: My vote of 2 PinmemberSrikanth Anandateertha5-Oct-11 6:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web02 | 2.8.141022.2 | Last Updated 5 Oct 2011
Article Copyright 2011 by Srikanth Anandateertha
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid