-
Hiding input password
Im trying to make an login menu in Visual studio 6.0. I want the password to be typed in as '*' , so you cant se the real password on the screen. Im building a MS-DOS interface. Here is the code we allready have tried and it didn't work..
#include <iostream.h>
#include <conio.h>
main ()
{
int c=0;
char buffer[20];
char a;
char n[11];
cout << "Name: ";
cin >> n;
cout << "Password: ";
while(a != '\n')
{
a=getch();
buffer[c]=a;
cout<<"*";
c++;
}
cout<<buffer;
return 0;
}
-
You can't use old type I/O, (getch), and stream I/O, (cout, cin), on the same channel at the same time without problems. Use one or the other.
-
It is always better to continue these threads on the board rather than take it to e-mail. First, I am not in the office that often, you were lucky, second, nobody else learns anything!
Code:
#include <stdio.h>
#include <conio.h>
main ()
{
int c=0;
char buffer[20];
char a;
char n[11];
bool Continue = 1;
printf("Name: ");
scanf("%s",&n);
printf("Password: ");
while (Continue)
{
a=getch();
if (a == 13)
{
Continue = 0;
buffer[c] = 0;
}
else
{
buffer[c]=a;
printf("*");
c++;
}
};
printf("\n%s\n",buffer);
return 0;
}
This is a bit nasty as I didn't have a lot of time, but basically works with VC6.