Thread: How can i change the password input to (*) ? Thanks, newbie here

  1. #1
    Registered User
    Join Date
    Mar 2015
    Location
    Las PiƱas, Philippines
    Posts
    1

    How can i change the password input to (*) ? Thanks, newbie here

    Code:
    
    
    Code:
    #include <iostream>
    #include <string>
     
    using namespace std;
     
    int main()
    {
         
        string password = "emiliani";
        string passwordEntry;
        int attempts = 1;
         
        cout << "Please enter your password: ";
        getline(cin, passwordEntry, '\n');
         
        while ( passwordEntry != password && attempts <=4 )
        {
            cout << "Please try again: ";
            getline(cin, passwordEntry, '\n');
            attempts++;    
        }
         
        if ( passwordEntry == password && attempts <=5 )
        {
            cout << "Access granted";  
        }
        else
        {
            cout << "Maximum attempts reached! The program will terminate!";
        }
       
    }

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    This cannot be done with standard C++, though it can be done with the help of non-standard libraries.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    what operating system/compiler?
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  4. #4
    Registered User Alpo's Avatar
    Join Date
    Apr 2014
    Posts
    877
    Couldn't you just traverse the string and subtract each value from the destination '*'? For example (in ASCII)

    char/value/difference with '*'
    A / 65 / -23
    l / 108 / -66
    p / 112 / -70
    o / 111 / -69

    Adding the difference to each letter produces the string ****, while subtracting the differences from **** produces the original string again.
    WndProc = (2[b] || !(2[b])) ? SufferNobly : TakeArms;

  5. #5
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    But since the console is line-buffered, the password would be visible as it was typed.

    @OP: Somewhere in the FAQ are OS-specific examples of how to do this very thing.

  6. #6
    Tweaking master Aslaville's Avatar
    Join Date
    Sep 2012
    Location
    Rogueport
    Posts
    528
    Probably this POSIX 1003.1 - man page for ioctl (posix section 3posix) - Unix & Linux Commands might come in hardy.

    Edit: Though the page itself might be a little outdated.

  7. #7

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Want input in password format
    By Lokesh in forum C Programming
    Replies: 3
    Last Post: 10-30-2007, 02:18 PM
  2. Input a password and replace with *s
    By Abda92 in forum C Programming
    Replies: 45
    Last Post: 10-06-2007, 03:52 PM
  3. Masking password input
    By cboard_member in forum C++ Programming
    Replies: 9
    Last Post: 07-18-2005, 06:47 PM
  4. mask password input
    By charleswong in forum Linux Programming
    Replies: 2
    Last Post: 04-25-2004, 11:02 PM
  5. Hiding input password
    By kagemand in forum C++ Programming
    Replies: 2
    Last Post: 11-23-2001, 08:32 AM