Thread: A Stable Password Protection Program Like Facebook (Best Run in Turbo C++ 3.1)

  1. #1
    Registered User DevoAjit's Avatar
    Join Date
    Jun 2011
    Location
    Ludhiana, Punjab, India, India
    Posts
    32

    A Stable Password Protection Program Like Facebook (Best Run in Turbo C++ 3.1)

    Code:
    /*:cool: Guys, This program make a file when its run. Run it and Understand it. and tell me, "can i improve in it more?*/
    #include<stdio.h>
    #include<conio.h>
    #include<string.h>
    void main()
    {
          char user[20],fltp[5]=".txt",flname[25],pswrd[35],cnfrm[35],login[35],pchek[35],c,ps,cn,lg;
          int i,j,k,l;
          FILE *usr;
          clrscr();
          gotoxy(25,23);
          textcolor(12);
          cprintf("Enter Your name:");//Note: this may be works as your username also. Name will be unique.
          scanf("%s",&user);//Scanf ko graphical bna. entry control
          strcpy(flname,user);
          strcat(flname,fltp);
          usr=fopen(flname,"r");
          if(usr==NULL)
          {
                       usr=fopen(flname,"w");
                       fprintf(usr,"Username: %s",user);
                       printf("Welcome!\nYou are a new user\nCreat your password below");
                       printf("\nEnter Password:");
                       retry:
                       j=0;
                       while((ps=getch())!=13)
                       {
                           printf("*");
                           pswrd[j]=ps;
                           j++;
                       }
                       pswrd[j]='\0';
                       printf("\nConfirm Password:");
                       k=0;
                       while((cn=getch())!=13)
                       {
                           printf("*");
                           cnfrm[k]=cn;
                           k++;
                       }
                       cnfrm[k]='\0';
                       if((strcmp(pswrd,cnfrm))==0)
                       {
                          fprintf(usr,"\nPassword: %s",cnfrm);
                          fclose(usr);
                       }
                       else
                       {
                           printf("Password didn't match! Try Again...\n");
                           printf("Enter password again:");
                           goto retry;
                       }
          }
    else
    {    gotoxy(25,25);
         cprintf("Password:");
         l=0;
         while((lg=getch())!=13)
         {
               printf("*");
               login[l]=lg;
               l++;
         }
         login[l]='\0';
         i=0;
          while((c=getc(usr))!= EOF)
          {
              if(c=='\n')
              {
                 fseek(usr,10,1);
                 while((c=getc(usr))!= EOF)
                 {
                       pchek[i]=c;
                       i++;
                 }
              }
          }
          pchek[i]='\0';
          if((strcmp(login,pchek))==0)
          {
             gotoxy(25,27);
             textcolor(11);
             cprintf("Welcome Back %s",user);
          }
          else
          {
              gotoxy(19,27);
              textcolor(11);
              cprintf("Wrong Password! You are not authorised");
          }
    }
          getch();
    }

  2. #2
    Registered User ledow's Avatar
    Join Date
    Dec 2011
    Posts
    435
    Find out yourself by running it through a vaguely-modern compiler:

    ..\test.c:4: warning: return type of 'main' is not 'int'
    ..\test.c:13: warning: format '%s' expects type 'char *', but argument 2 has type 'char (*)[20]'

    And all the conio stuff isn't even present on most modern setups at all - very Turbo-C specific. And you mis-indented the outer-most if.

    - Compiler warnings are like "Bridge Out Ahead" warnings. DON'T just ignore them.
    - A compiler error is something SO stupid that the compiler genuinely can't carry on with its job. A compiler warning is the compiler saying "Well, that's bloody stupid but if you WANT to ignore me..." and carrying on.
    - The best debugging tool in the world is a bunch of printf()'s for everything important around the bits you think might be wrong.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    You could also try using proper words for your variable names.

    Nothing is served by ripping out the vowels from variable names.

    Also, backward 'goto' statements should equate to some kind of loop construct.

    Also, try writing some of the code as functions. 100+ line functions are so much harder to write / test / maintain.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User gardhr's Avatar
    Join Date
    Apr 2011
    Posts
    151
    Quote Originally Posted by DevoAjit View Post
    A Stable Password Protection Program Like Facebook
    Sorry, your program is neither stable nor secure, and lacks even the most basic level of encapsulation. Read up on buffer overflows and how to prevent them, and consider storing a hash or some such rather than the password itself in the file. Good luck!

  5. #5
    Registered User
    Join Date
    Dec 2011
    Posts
    795
    This is just...awful:

    • Don't use numbers for character constants. I have no idea what "13" represents in the getch loop.
    • Don't shove all of your code into one main function, split it up.
    • Learn how to do error checking to make sure that your function calls work.
    • Learn about buffer overflows
    • Lose all the Turbo-C ........, meaning anything from the conio.h library, cprintf(), gotoxy(), clrscr() and getch().
    • Replace void main() with the shell:
      Code:
      int main (void) { return 0; }
    • Get rid of all the goto spaghetti code and learn how to use a loop.
    • Don't compare with a getc loop because it's very inefficient. Read everything into a buffer and strcmp().
    • If you're expecting security, why are you writing the passwords to an unencrypted file?
    • Learn how to indent. Your code is twice as annoying to read when it looks like a heap of mess.
    • Learn to manage file handles, that means closing them when your program exits.


    There's a lot more stuff but you should probably just scrap this and re-write.

  6. #6
    Registered User javaeyes's Avatar
    Join Date
    Feb 2012
    Posts
    153
    Is there a reason you're doing this in c -- and Turbo c at that? You may be better off with PHP/PERL+MYSQL+a hashing algorithm.

  7. #7
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Tubro C++? That belongs in a museum. Surely they were barely past using punch cards to program when that was last used. I mean I know you're in a different time zone, I just didn't realise you were several decades behind.
    You can't even run anything that produces on a 64-bit OS.

    You may as well be asking us to help you paint the mona lisa on your first week of learning to paint. It just aint gonna happen. Real security take real years of knowledge to learn.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  8. #8
    Registered User
    Join Date
    Jan 2009
    Posts
    1,485
    The only thing one would have to do to break it, is to enter a user name longer than 20 characters.

  9. #9
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    Yay .. this is the "Pick on the Turbo C++ guy" day !
    Thankfully.. we are having those days less frequently nowadays....it seems from the zeal of the posts here.

  10. #10
    Registered User
    Join Date
    Jan 2009
    Posts
    1,485
    Quote Originally Posted by manasij7479 View Post
    Yay .. this is the "Pick on the Turbo C++ guy" day !
    Thankfully.. we are having those days less frequently nowadays....it seems from the zeal of the posts here.
    The guy is asking for critique and ways to improve it in the comment made at the top of the code. All people are doing is to respond to that request.

  11. #11
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    Quote Originally Posted by Subsonics View Post
    The guy is asking for critique and ways to improve it in the comment made at the top of the code. All people are doing is to respond to that request.
    A Stable Password Protection Program Like Facebook (Best Run in Turbo C++ 3.1)-you_dont_say_brown_egg_vs_white_egg-s299x220-244800-580-jpg

  12. #12
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    your program is neither stable nor secure
    O_o Facebook is stable and secure? o_O

    Soma

  13. #13
    Registered User
    Join Date
    Jan 2009
    Posts
    1,485
    @manasij7479: So what's the point of you last two comments then, trolling? If so congrats, mission accomplished.

    I take it you think my response to you was blatantly obvious, but if it was, then why did you post the first one?
    Last edited by Subsonics; 04-14-2012 at 02:47 PM.

  14. #14
    Registered User DevoAjit's Avatar
    Join Date
    Jun 2011
    Location
    Ludhiana, Punjab, India, India
    Posts
    32
    Quote Originally Posted by ledow View Post
    Find out yourself by running it through a vaguely-modern compiler:
    tell me a new modern compiler so i can download. beacause i m a new bee in programming, so i dont know more about it.

  15. #15
    Registered User DevoAjit's Avatar
    Join Date
    Jun 2011
    Location
    Ludhiana, Punjab, India, India
    Posts
    32
    Quote Originally Posted by Salem View Post
    You could also try using proper words for your variable names.
    yah, next time i will take care of it.

    Quote Originally Posted by Salem View Post
    Also, try writing some of the code as functions. 100+ line functions are so much harder to write / test / maintain.
    i was thought so. Next time, my programmes will be in better understanding.
    thanks salem.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. password protection programme
    By meharsri in forum C Programming
    Replies: 2
    Last Post: 02-27-2011, 06:01 PM
  2. Replies: 2
    Last Post: 01-07-2009, 10:35 AM
  3. password protection for xml file
    By anil_beloved in forum Windows Programming
    Replies: 0
    Last Post: 06-27-2005, 08:44 AM
  4. Best software copy protection program
    By axr0284 in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 12-09-2004, 09:07 AM
  5. Screen program protection?
    By biosninja in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 09-10-2002, 11:48 PM

Tags for this Thread