hiding user input

how can I hide user input and still stores the input in a variable and later print out on the screen?
This is specific to the terminal being used for user input, which is thus specific tpo your operating system.

http://www.cplusplus.com/articles/E6vU7k9E/
#include <iostream>
#include <conio.h>
#include <stdlib.h>
using namespace std; //needed for cout and etc

int main()
{
START:
system("cls");
cout<<"\nEnter Password : ";
char pass[32];//to store password.
int i = 0;
char a;//a Temp char
for(i=0;;)//infinite loop
{
a=getch();//stores char typed in a
if((a>='a'&&a<='z')||(a>='A'&&a<='Z')||(a>='0'&&a<='9'))
//check if a is numeric or alphabet
{
pass[i]=a;//stores a in pass
++i;
cout<<"*";
}
if(a=='\b'&&i>=1)//if user typed backspace
//i should be greater than 1.
{
cout<<"\b \b";//rub the character behind the cursor.
--i;
}
if(a=='\r')//if enter is pressed
{
pass[i]='\0';//null means end of string.
break;//break the loop
}
}
cout<<"\nYou entered : "<<pass;
//here we can even check for minimum digits needed
if(i<=5)
{
cout<<"\nMinimum 6 digits needed.\nEnter Again";
getch();//It was not pausing :p
goto START;
}
return 0;
}
Topic archived. No new replies allowed.