Thread: C++ Password mask

  1. #1
    Registered User
    Join Date
    Dec 2009

    C++ Password mask

    I just started messing around with making a password on a simple program. Can anyone here tell me how to, and explain, how to make asterisks appear when the user is enter the password? I searched a little but the few results i found, I didn't completely understand. Thanks

    #include <iostream>
    #include <string>
    using namespace std;
    int main()
              string str1 = "suzuki";
              string password ;
              cout << "Enter Password\n";
              getline(cin, password);
                          if(password != str1)
                                      cout << "Error, try again\n";
                                      while(password != str1);
              int num1, num2;
                  cout << "Enter a number to add\n";
                  cin >> num1;
                  cout << "Enter a nother num\n";
                  cin >> num2;
                  cout << " Total is " << num1 + num2 << endl;
                  return 0;

  2. #2
    30 Helens Agree neandrake's Avatar
    Join Date
    Jan 2002
    You won't be able to use standard cin/cout to mask input. On a quick search it looks like you may need to use the C function getch(). Search for "c++ mask input", and there are plenty of results with people asking for the same thing.
    Environment: OS X, GCC / G++
    Codes: Java, C#, C/C++
    AOL IM: neandrake, Email: neandrake (at) gmail (dot) com

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    As neandrake says, there is nothing standard to help you do this.

    So you need to find some function which is specific to your OS/Compiler to do this.
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Weird problem with an array of vector<char *>'s ???
    By phummon in forum C++ Programming
    Replies: 2
    Last Post: 05-02-2010, 05:39 PM
  2. [Q]Hide Password
    By Yuri in forum C++ Programming
    Replies: 14
    Last Post: 03-02-2006, 03:42 AM
  3. mask password input
    By charleswong in forum Linux Programming
    Replies: 2
    Last Post: 04-25-2004, 11:02 PM
  4. C diamonds and perls :)
    By Carlos in forum A Brief History of
    Replies: 7
    Last Post: 05-16-2003, 10:19 PM
  5. Replies: 3
    Last Post: 12-15-2001, 01:46 PM