Click here to Skip to main content
15,906,766 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralEntering a password in the Command Prompt Pin
Alvaro Mendez7-Nov-01 11:50
Alvaro Mendez7-Nov-01 11:50 
GeneralRe: Entering a password in the Command Prompt Pin
Chris Losinger7-Nov-01 12:02
professionalChris Losinger7-Nov-01 12:02 
GeneralRe: Entering a password in the Command Prompt Pin
Alvaro Mendez7-Nov-01 12:17
Alvaro Mendez7-Nov-01 12:17 
GeneralRe: Entering a password in the Command Prompt Pin
Nish Nishant7-Nov-01 13:57
sitebuilderNish Nishant7-Nov-01 13:57 
GeneralRe: Entering a password in the Command Prompt Pin
Michael P Butler7-Nov-01 22:01
Michael P Butler7-Nov-01 22:01 
GeneralRe: Entering a password in the Command Prompt Pin
Nish Nishant7-Nov-01 22:23
sitebuilderNish Nishant7-Nov-01 22:23 
GeneralRe: Entering a password in the Command Prompt Pin
Alvaro Mendez8-Nov-01 5:28
Alvaro Mendez8-Nov-01 5:28 
GeneralRe: Entering a password in the Command Prompt Pin
Alvaro Mendez8-Nov-01 6:16
Alvaro Mendez8-Nov-01 6:16 
Well, I got it working so that it doesn't show any characters. It's not as pretty as the masked solution, but it's easier and it works. Here's the code for the method, in case someone's interested:

string getPrompt(const char* szPrompt, bool bShow = true)
{
	cout << szPrompt << ": ";
 
	char szResponse[80];
 
	if (bShow)
		cin.getline(szResponse, sizeof(szResponse));
	else
	{
		#ifdef _WIN32
			int iPos = 0;
			for (int c = 0; (c = getch()) != '\r'; )
			{      
				if (c == '\b')
				{
					if (iPos > 0)
						iPos--;
				}
				else if (isprint(c) && iPos < sizeof(szResponse) - 1)
					szResponse[iPos++] = c;
			}
			szResponse[iPos] = 0;
		#else
			system("stty -echo");
			cin.getline(szResponse, sizeof(szResponse));
			system("stty echo");
		#endif
	}

	return szResponse;
}


Thanks for your assistance.
Alvaro
GeneralRe: Entering a password in the Command Prompt Pin
Joaquín M López Muñoz7-Nov-01 12:20
Joaquín M López Muñoz7-Nov-01 12:20 
QuestionLoops and MFC? Pin
7-Nov-01 11:16
suss7-Nov-01 11:16 
AnswerRe: Loops and MFC? Pin
Stan Shannon7-Nov-01 11:24
Stan Shannon7-Nov-01 11:24 
GeneralRe: Loops and MFC? Pin
7-Nov-01 11:31
suss7-Nov-01 11:31 
GeneralRe: Loops and MFC? Pin
7-Nov-01 11:38
suss7-Nov-01 11:38 
GeneralRe: Loops and MFC? Pin
Alvaro Mendez7-Nov-01 11:59
Alvaro Mendez7-Nov-01 11:59 
GeneralRe: Loops and MFC? Pin
7-Nov-01 14:30
suss7-Nov-01 14:30 
GeneralRe: Loops and MFC? Pin
Michael Dunn7-Nov-01 15:25
sitebuilderMichael Dunn7-Nov-01 15:25 
Question2 problems. Any takers? Pin
ParaSwarm7-Nov-01 11:10
ParaSwarm7-Nov-01 11:10 
AnswerRe: 2 problems. Any takers? Pin
Joaquín M López Muñoz7-Nov-01 11:30
Joaquín M López Muñoz7-Nov-01 11:30 
AnswerRe: 2 problems. Any takers? Pin
Anders Molin7-Nov-01 12:00
professionalAnders Molin7-Nov-01 12:00 
AnswerRe: 2 problems. Any takers? Pin
Alvaro Mendez7-Nov-01 12:25
Alvaro Mendez7-Nov-01 12:25 
GeneralDialog box application Pin
7-Nov-01 9:51
suss7-Nov-01 9:51 
GeneralRe: Dialog box application Pin
Ravi Bhavnani7-Nov-01 9:57
professionalRavi Bhavnani7-Nov-01 9:57 
GeneralRe: Dialog box application Pin
7-Nov-01 10:09
suss7-Nov-01 10:09 
QuestionHow can I access VC++/MSDN help from outside DevStudio? Pin
7-Nov-01 9:16
suss7-Nov-01 9:16 
GeneralList View Help! Pin
gas7-Nov-01 8:11
gas7-Nov-01 8:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.