Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: C++ Password character echo

  1. Jul 14, 2010 #1
    The problem statement, all variables and given/known data

    Currently using stdio.h, conio.h, string.h, stdlib.h
    not using iostream, namespace std etc.

    I am asked to make a password prompt where each character echoes an asterisk (*)

    The user must be able to backspace and delete to make corrections.

    The password is then stored in an array which can accomodate up to 100 passwords.

    The attempt at a solution

    while(c != eof())
    if (c != eof())
    pw[userid][count] = '\0';

    sadly, the output indentation looks horrible and it is uneditable using backspace and delete.
  2. jcsd
  3. Jul 15, 2010 #2


    User Avatar
    Science Advisor

    As I recall, getch returns any key presses. This includes control characters, such as, say, the backspace character (ASCII 0x08):

    You might also want to do some input filtering to ensure that only characters you want accepted actually are (again, look at the ASCII table). Lastly, rather than go crazy with allowing the user to edit and change the password, you might want to consider using a "Please type password again", just to make sure the user is entering both the same.

    Good luck!
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook