How to give privacy to a program?

Discussion in 'Computer Science | IT | Networking' started by Vishal0203, Jul 13, 2012.

    Vishal0203 Apprentice

    Message Count:
    240
    Ratings Received:
    +53
    Engineering Discipline:
    Computer Science
    I created this program, which is later connected to another code to form a software..
    Actually, now I want to make my software private. I mean, it must work on a particular system but, when pirated and tried to run on some other system, it must not work.
    while surfing on internet I found that the IP address of a system is the unique code for every pc. Is there any way to keep my software private such that it runs on a particular ip address??

    here's the half-code:

    Code:
    #include<conio.h>
    #include<stdio.h>
    #include<string.h>
    #include<dos.h>
    #include<stdlib.h>
     
    static int i=0;
    struct web
    {
    char name[30],pass[30];
    }w[100];
    int n;
    int login(void);
    int reg(void);
    int main()
    {
    system("cls");
    printf("\n\n\n\n\n\n\t\t\tWELCOME TO C WORLD!!");
    printf("\n\t\t\t^^^^^^^^^^^^^^^^^^^^");
    printf("\n\n\n\n\t\t\tPress Enter to proceed...");
    if(getche()==13)
      system("cls");
    XY:
    printf("\n\n\n\t\t\t1. LOGIN\t\t2. REGISTER");
    printf("\n\n\n\t\t\t\tENTER YOUR CHOICE: ");
    scanf("%d",&n);
    switch(n)
      {
        case 1:  system("cls");
            login();
            break;
        case 2:  system("cls");
            reg();
            break;
        default: printf("\n\n\t\t\t\tNO MATCH FOUND");
            printf("\n\n\t\t\tPress Enter to re-Enter the choice");
            if(getche()==13)
            system("cls");
            goto XY;
     
      }
      return 0;
    }
    int reg()
      {
        FILE *fp;
        char c,checker[30]; int z=0,j=0;
        fp=fopen("Web_reg.txt","ab+");
        printf("\n\n\t\t\t\tWELCOME TO REGISTER ZONE");
        printf("\n\t\t\t\t^^^^^^^^^^^^^^^^^^^^^^^^");
        for(i=0;i<100;i++)
        {
          printf("\n\n\t\t\t\t  ENTER USERNAME: ");
          scanf("%s",checker);
            while(!feof(fp))
            {
            for(j=0;j<100;j++)
            {
              fread(&w[j],sizeof(w[j]),1,fp);
              if(strcmp(checker,w[j].name)==0)
                {
                printf("\n\n\t\t\tUSERNAME ALREDY EXISTS");
                fclose(fp);
                reg();
                break;
                }
            }
                strcpy(w[i].name,checker);
                fclose(fp);
                break;
            }
          fp=fopen("Web_reg.txt","ab+");
          printf("\n\n\t\t\t\t  DESIRED PASSWORD: ");
          while((c=getch())!=13)
            {
              w[i].pass[z++]=c;
              printf("%c",'*');
            }
          w[i].pass[z]='\0';
          fwrite(&w[i],sizeof(w[i]),1,fp);
          fclose(fp);
          printf("\n\n\tPress enter if you agree with Username and Password");
          if(getche()==13)
            {
            system("cls");
            printf("\n\n\t\t\t\tTHANK YOU FOR REGISTERING");
            printf("\n\n\t\t\tYOU ARE SUCCESSFULLY REGISTERED");
            printf("\n\n\n\t\t Press Enter to Login your account");
            if(getche()==13)
              {
                system("cls");
                login();
                break;
              }
     
            }
              break;
          }
        getch();
        return 0;
      }
     
      int login()
        {
          FILE *fp;
          char c,name[30],pass[30]; int z=0;
          int checku,checkp;
          fp=fopen("Web_reg.txt","rb");
          printf("\n\n\t\t\t\tWELCOME TO LOG IN ZONE");
          printf("\n\t\t\t\t^^^^^^^^^^^^^^^^^^^^^^");
            printf("\n\n\t\t\t\t  ENTER USERNAME: ");
            scanf("%s",name);
            printf("\n\n\t\t\t\t  ENTER PASSWORD: ");
            while((c=getch())!=13)
            {
              pass[z++]=c;
              printf("%c",'*');
            }
            pass[z]='\0';
          while(!feof(fp))
            {
            for(i=0;i<100;i++)
            {
              fread(&w[i],sizeof(w[i]),1,fp);
              checku=strcmp(name,w[i].name);
              checkp=strcmp(pass,w[i].pass);
              if(checku==0&&checkp==0)
                break;
            }
              if(checku==0&&checkp==0)
              {
                system("cls");
                printf("\n\n\n\t\t\tYOU HAVE LOGGED IN SUCCESSFULLY!!");
                printf("\n\n\n\t\t\t\tWELCOME!!");
                break;
              }
            else
              {
                printf("\n\n\n\t\t\tYou are not a Registered User\n \t\t\tPress enter to register yourself");
                if(getch()==13)
                {
                system("cls");
                reg();
                }
     
              }
     
          break;
          }
          getch();
          return 0;
        }
    

    Uday Bidkar Certified CEan

    Message Count:
    13
    Ratings Received:
    +8
    Engineering Discipline:
    IT
    Don't use IP in your code to restrict it to a machine, as it "may" change the next time when you come online (depends upon the DHCP server). Use MAC address instead (http://en.wikipedia.org/wiki/MAC_address). You can find plenty of examples to get the MAC address of the machine programatically (e.g. http://stackoverflow.com/questions/1779715/how-to-get-mac-address-of-your-machine-using-a-c-program). If you are using windows, running ipconfig/all from command line will reveal the MAC of your machine against "Physical Address". On unix/linux ifconfig should give you this information.
    • Like Like x 3

    Vishal0203 Apprentice

    Message Count:
    240
    Ratings Received:
    +53
    Engineering Discipline:
    Computer Science
    Yeah, using MAC address is good! I could get the MAC address for my pc using the code, but how to use it to avoid the misuse of the software?
    how to store this MAC address?? How to compare it with the MAC address of some other pc?

    Uday Bidkar Certified CEan

    Message Count:
    13
    Ratings Received:
    +8
    Engineering Discipline:
    IT
    I don't understand, if you have mac of your machine and a way to get it programatically, why can't you just store your machine's mac as a string in your program and compare to one you get programatically in your code? If it's the same, proceed, if different, abort, or am I missing something here?
    • The MOD Squad

    Harshad Italiya Moderator

    Message Count:
    7,582
    Ratings Received:
    +508
    Engineering Discipline:
    Electronics & Communications
    In our company we had used MAC ID to protect one of our Application its the best way to protect your code or application.

    Vishal0203 Apprentice

    Message Count:
    240
    Ratings Received:
    +53
    Engineering Discipline:
    Computer Science
    If i store the MAC address of my system as a string, then the software will be running only in my system, in that way I'll not be able to distribute it to anyone. :| Am I right???

    Vishal0203 Apprentice

    Message Count:
    240
    Ratings Received:
    +53
    Engineering Discipline:
    Computer Science
    I think your company used MAC code, to protect the app from employees. I mean, the application may be used only in the company no one can use it outside the company!
    • The MOD Squad

    Harshad Italiya Moderator

    Message Count:
    7,582
    Ratings Received:
    +508
    Engineering Discipline:
    Electronics & Communications
    If you want to distribute it then you can add such routine which asks you first to enter Password or something like that.
    • The MOD Squad

    Harshad Italiya Moderator

    Message Count:
    7,582
    Ratings Received:
    +508
    Engineering Discipline:
    Electronics & Communications
    No in our case we have to do installation at client PC so we made small routine which was first checking for MAC and after that we make it as a security in Final Application.

    Vishal0203 Apprentice

    Message Count:
    240
    Ratings Received:
    +53
    Engineering Discipline:
    Computer Science
    I tried that, but if the other person gives the installer to his friend or anyone, even that person will be able to login using username and password provided to the 1st user.
    I think password would be helpful, if the software is network based!
    • The MOD Squad

    Harshad Italiya Moderator

    Message Count:
    7,582
    Ratings Received:
    +508
    Engineering Discipline:
    Electronics & Communications
    Then there is one more option first ask them to send you MAC ID of their PC then implement in your software. So perticular that software will work only on that PC if they want to change PC charge them Extra.
    • Like Like x 1

    Vishal0203 Apprentice

    Message Count:
    240
    Ratings Received:
    +53
    Engineering Discipline:
    Computer Science
    Nice idea.. :) it'll be good.. Hope they know how to get the MAC address.. Anyway, I'm gonna try for that now.

    Hahaha.. or else, I can even say that, "You bought it using your money, why are you giving it to someone else, who has not payed for it" :rofl: may be, this will click the selfish nature of a human being.. :sneaky:

    Vishal0203 Apprentice

    Message Count:
    240
    Ratings Received:
    +53
    Engineering Discipline:
    Computer Science
    @godfather do you have any idea? how to extract MAC address using C in windows??? I surfed the entire internet, but i could find it only for LINUX
    • The MOD Squad

    Harshad Italiya Moderator

    Message Count:
    7,582
    Ratings Received:
    +508
    Engineering Discipline:
    Electronics & Communications
    Not sure but there should be such app which can get MAC address.

    Vishal0203 Apprentice

    Message Count:
    240
    Ratings Received:
    +53
    Engineering Discipline:
    Computer Science
    using command prompt we can see the address but, it is of no use until we can extract it

    Uday Bidkar Certified CEan

    Message Count:
    13
    Ratings Received:
    +8
    Engineering Discipline:
    IT
    Well, if you can't find anything, a crud way will be to use system() to call getmac or ipconfig/all redirecting the output to a file, read the file and parse it to get mac out of it.

    Vishal0203 Apprentice

    Message Count:
    240
    Ratings Received:
    +53
    Engineering Discipline:
    Computer Science
    Hey, I could get the address using the following code, but how to store the things present on output screen to a file???

    Code:
    #include<conio.h>
    #include<stdlib.h>
    int main()
     
    {
        system("ipconfig/all");
        getch();
            return 0;
    }
    

    [Prototype] Ace

    Message Count:
    748
    Ratings Received:
    +165
    Engineering Discipline:
    Electronics
    The best way is always to generate a GUID.
    Other possible methods could be generating a uid based on the processor id or mobo id. Problem with this technique is that, few of the processor/mobo do not have these, but most of the machine will have it.

    You can also use online authentication system, but it'll require internet on clients computer before it can be used.

    Uday Bidkar Certified CEan

    Message Count:
    13
    Ratings Received:
    +8
    Engineering Discipline:
    IT
    Try system("ipconfig/all > ipconfig.txt");
    • Like Like x 1

    Vishal0203 Apprentice

    Message Count:
    240
    Ratings Received:
    +53
    Engineering Discipline:
    Computer Science
    I thought of that before, but yea, it'll need internet connection, as well as, i'll have to connect the software to internet, which is not possible using C.

Share This Page