Thread: Passwords

  1. #1
    Unregistered
    Guest

    Unhappy Passwords

    I would like to know how to get a user to enter a password without echoing it to the screen.
    This code works but NOT if you press the backspace key when you make a mistake. Any Suggestions ?


    fprintf(stdout,"\nEnter password: ");
    while((ch = getch()) != '\r' && counter < CONNECT)
    {
    user_input[counter++] = ch;
    fputc('*',stdout);
    }

    BigSteve

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,484
    Code:
    if ( ch == '\b' && counter > 0 ) {
        counter--;
    } else {
        user_input[counter++] = ch;
    }
    Some kind of test for backspace should have been self-evident.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. vBulletin vandals and the wisdom of randomly generated passwords
    By abachler in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 12-08-2008, 05:27 PM
  2. Deleting IE saved user names and passwords
    By patrick22 in forum Windows Programming
    Replies: 3
    Last Post: 03-23-2008, 04:38 PM
  3. Database programming and passwords
    By Squintz in forum Windows Programming
    Replies: 6
    Last Post: 11-19-2003, 09:05 PM
  4. Encrypting and checking passwords in bigger programs
    By TerryBogard in forum C Programming
    Replies: 1
    Last Post: 11-17-2002, 07:21 AM
  5. What is the best way to use passwords?
    By GreenCherry in forum C++ Programming
    Replies: 1
    Last Post: 03-22-2002, 11:37 AM