C++ code for password entry

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tcsvikr
    New Member
    • Feb 2007
    • 18

    C++ code for password entry

    Hi,
    I'm a newbie in c++...Can anyone provide me with the C++ code for entering the password...It should be in this way..
    The user enters the password but only *'s should be displayed...Ass ume that there is a flat file which contains the details of users and their respective passwords. Authentication should be provided after checking the file...

    Its urgent..Thanks in advance...
    Regards
    vijay
  • Meetee
    Recognized Expert Contributor
    • Dec 2006
    • 928

    #2
    Originally posted by tcsvikr
    Hi,
    I'm a newbie in c++...Can anyone provide me with the C++ code for entering the password...It should be in this way..
    The user enters the password but only *'s should be displayed...Ass ume that there is a flat file which contains the details of users and their respective passwords. Authentication should be provided after checking the file...

    Its urgent..Thanks in advance...
    Regards
    vijay
    Hi Vijay,

    Welcome to TSDN. What have you done so far? We cannot provide you direct code as per posting guidelines. Kindly post your perticular problem and paste your efforts in code tags so that we can help you.

    Google is a friend always!

    Regards

    Comment

    • ashitpro
      Recognized Expert Contributor
      • Aug 2007
      • 542

      #3
      [code=c]#include<stdio. h>
      #include<conio. h>
      int main()
      {
      char ch;
      char pass[20];
      int i=0;
      while((ch=getch ())!=13 && i < 20) //13 is ascii value for "Enter" key, I am not sure.
      {
      printf("*");
      pass[i++]=ch;
      }
      //here pass will contain your password.
      }
      [/code]
      This code will work if you have conio.h file.
      On posix platform probably you need to download "kbhit" and use kbhit instead of getch in above code.
      Last edited by sicarie; Oct 22 '07, 01:13 PM. Reason: Code tags

      Comment

      • sicarie
        Recognized Expert Specialist
        • Nov 2006
        • 4677

        #4
        Originally posted by ashitpro
        [code=c]#include<stdio. h>
        #include<conio. h>
        int main()
        {
        char ch;
        char pass[20];
        int i=0;
        while((ch=getch ())!=13 && i < 20) //13 is ascii value for "Enter" key, I am not sure.
        {
        printf("*");
        pass[i++]=ch;
        }
        //here pass will contain your password.
        }
        [/code]
        This code will work if you have conio.h file.
        On posix platform probably you need to download "kbhit" and use kbhit instead of getch in above code.
        A note on the above - using conio.h means that you are using a non standard header and this will not work on all machines. If you are going to deploy this to a mass number of machines, I would recommend thorough testing to make sure they are all compatible, or finding another method of implementation.

        @ashitpro - you are a member now, and thus expected to know when and how to use code tags. If you need to, please review when and how to use code tags.

        Comment

        Working...