Give it a little help lifeless programmes :)

How can i make my password appears as stars ! It's really stupid that it appears as i write , i know there is no getche() in c++ , so help me with this !
system("cls");
cout<<"Enter Your Usename Please:"<<endl;
cin>>adminuser;
cout<<"Enter Your Password Please:"<<endl;
cin>>adminpassword;
if(adminuser=="pouya" && adminpassword=="admin"){ Admin.AdminIntro();}
else { cout<<"Sorry, Information Entered Is Invalid"<<endl;}
system("pause");
system("cls");
you need to hide the input, you can include conio.h and use the getch() function to get chars then just output a star for each char received. a lot of people seem to not like conio.h though because it is very old.
and conio.h does work in c++

I am sure there are better and newer ways, that is just the only one I know of by memory
Dear Michaela Elise , I'v tried that , it wasn't successful, can you implement it on the segment of code I just posted ? if there is any other new way neither my lecturer and internet does not know , they all want to do it with getche() and getche() gives me an error , I'm using visual studio 2012 ....
Code from duoas

http://www.cplusplus.com/forum/general/3570/

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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <iostream>
#include <stdexcept>
#include <string>
#include <windows.h>
using namespace std;

string getpassword( const string& prompt = "Enter password> " )
  {
  string result;

  // Set the console mode to no-echo, not-line-buffered input
  DWORD mode, count;
  HANDLE ih = GetStdHandle( STD_INPUT_HANDLE  );
  HANDLE oh = GetStdHandle( STD_OUTPUT_HANDLE );
  if (!GetConsoleMode( ih, &mode ))
    throw runtime_error(
      "getpassword: You must be connected to a console to use this program.\n"
      );
  SetConsoleMode( ih, mode & ~(ENABLE_ECHO_INPUT | ENABLE_LINE_INPUT) );

  // Get the password string
  WriteConsoleA( oh, prompt.c_str(), prompt.length(), &count, NULL );
  char c;
  while (ReadConsoleA( ih, &c, 1, &count, NULL) && (c != '\r') && (c != '\n'))
    {
    if (c == '\b')
      {
      if (result.length())
        {
        WriteConsoleA( oh, "\b \b", 3, &count, NULL );
        result.erase( result.end() -1 );
        }
      }
    else
      {
      WriteConsoleA( oh, "*", 1, &count, NULL );
      result.push_back( c );
      }
    }

  // Restore the console mode
  SetConsoleMode( ih, mode );

  return result;
  }

int main()
  {
  try {

    string password = getpassword( "Enter a test password> " );
    cout << "\nYour password is " << password << endl;

    }
  catch (exception& e)
    {
    cerr << e.what();
    return 1;
    }

  return 0;
  }
Topic archived. No new replies allowed.