How to take passwords input as ****** or just nothing

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ppuniversal
    New Member
    • Feb 2007
    • 52

    How to take passwords input as ****** or just nothing

    Hello,
    I am making a console application in C++ where I have to take username and password as input from user.
    I want that when password is taken, it should not be shown on screen, i.e. it is either shown as asterix(******* ) or just no movement of cursor.

    Please Reply
    Pawan
  • horace1
    Recognized Expert Top Contributor
    • Nov 2006
    • 1510

    #2
    Originally posted by ppuniversal
    Hello,
    I am making a console application in C++ where I have to take username and password as input from user.
    I want that when password is taken, it should not be shown on screen, i.e. it is either shown as asterix(******* ) or just no movement of cursor.

    Please Reply
    Pawan
    some windows compilers have a header file <conio.h> with a function getch() which reads a character from the keyboard without echo .

    Comment

    • vermarajeev
      New Member
      • Aug 2006
      • 180

      #3
      Originally posted by horace1
      some windows compilers have a header file <conio.h> with a function getch() which reads a character from the keyboard without echo .
      Code:
      int main()
      {
         char ch;
         string password;
         while ( (ch = getch()) != '\r' )
         {  
               password.push_back(ch);
         }
         cout<< "You entered :"<< password<<endl;
         return 0;
      }
      You can use above code for windows, For Linux, there is something called getpass( char* ); type man getpass on console to see how it works.

      Comment

      • saranjegan
        New Member
        • Feb 2007
        • 50

        #4
        Originally posted by ppuniversal
        Hello,
        I am making a console application in C++ where I have to take username and password as input from user.
        I want that when password is taken, it should not be shown on screen, i.e. it is either shown as asterix(******* ) or just no movement of cursor.

        Please Reply
        Pawan
        use getpass function
        or print *** using getch and putch in a for loop

        Comment

        • ppuniversal
          New Member
          • Feb 2007
          • 52

          #5
          Originally posted by saranjegan
          use getpass function
          or print *** using getch and putch in a for loop
          What is this getpass() function, I didnt find it anywhere!
          Pawan

          Comment

          • ppuniversal
            New Member
            • Feb 2007
            • 52

            #6
            Originally posted by vermarajeev
            Code:
            int main()
            {
               char ch;
               string password;
               while ( (ch = getch()) != '\r' )
               {  
                     password.push_back(ch);
               }
               cout<< "You entered :"<< password<<endl;
               return 0;
            }
            You can use above code for windows, For Linux, there is something called getpass( char* ); type man getpass on console to see how it works.
            Thanks, it worked.
            Pawan

            Comment

            • Jathniel
              New Member
              • Mar 2007
              • 1

              #7
              nice. it works perfectly!!! thx, i've been searchin ds codes for ages..

              Comment

              Working...