Simple input prompt doesnt show

Hey everyone, im simply trying to get the user to enter the new username when creating a new account. Then, appending that information into the text file. My program does take the info and store it into the txt file. However, the problem is that the user's input does not show on the screen...
Also it counts backspace as a character and requires the user to press enter 2 times.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
cout<<"Please enter the following information to confirm your identity!"<<endl;
            cout<<"Enter your current username: ";
            cin>>currentuser;
            currentpass=getpass("Enter your current password: ",true);

            //confirms the user's identity, allows the user to create a new account
            if (currentuser==username&&currentpass==password){
               cout<<"Identity confirmed!"<<endl;


               cout<<"\nEnter the new username: ";
               cin>>newuser;//This is the problem
               
               newpass=getpass("\nEnter the new password: ",true);
               
               //opens the text file
               expassword.open("password.txt", ios::app);
               
               //appened the new account info into the text file
               expassword<<newuser<<endl;
               expassword<<newpass<<endl;
               
            }else{
                  cout<<"Incorrect username/password!"<<endl;
                  system("PAUSE");   
            }   
            //closes the text file
            expassword.close();
Last edited on
¿getpass() from unistd.h?
The manuals says `This function is obsolete. Do not use it.'

... nope, it only takes one argument, ¿which library are you using?
This is the function that i used to mask the passwords
and im using windows.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
string getpass(const char *prompt, bool show_asterisk=true)
{
  const char BACKSPACE=8;
  const char RETURN=13;

  string password;
  unsigned char ch=0;

  cout<<prompt;

  DWORD con_mode;
  DWORD dwRead;

  HANDLE hIn=GetStdHandle(STD_INPUT_HANDLE);

  GetConsoleMode( hIn, &con_mode );
  SetConsoleMode( hIn, con_mode & ~(ENABLE_ECHO_INPUT | ENABLE_LINE_INPUT) );

  while(ReadConsoleA( hIn, &ch, 1, &dwRead, NULL) && ch !=RETURN)
    {
       if(ch==BACKSPACE)
         {
            if(password.length()!=0)
              {
                 if(show_asterisk)
                     cout <<"\b \b";
                 password.resize(password.length()-1);
              }
         }
       else
         {
             password+=ch;
             if(show_asterisk)
                 cout <<'*';
         }
    }
  cout <<endl;
  return password;
}
When you are done reading the password, restore the console to its previous state (with echoing)

It shouldn't count backspace as a character (unless it is not simply 8), examine `password' (with a debugger)
Here's a getpassword() function for you.
http://www.cplusplus.com/forum/general/3570/#msg15410

Notice how my function does not mix WinAPI I/O and C++ stream I/O, and it does not hardcode ASCII values but instead uses the proper C/C++ escape codes for CR and BS.

It doesn't have the option to not use asterisks -- you can add that easily enough if you want, just like your routine does above.

(Ignore the other yahoo from "big IT firm " in that thread.)

Hope this helps.
Topic archived. No new replies allowed.