How to hide/mask user input in C++ console applications

CaptainKahuna

Platinum Member
May 19, 2002
2,228
0
0
www.billda.com
My program has a password field, and I need to know how to hide or mask the users password as he types it in. I would be fine with using "*"s, or simply not displaying anything as he types. Thanks.
 

HJB417

Senior member
Dec 31, 2000
763
0
0
I think you might need to use conio.h, I've never used the library before but quickly looking at the functions names, I think getch might do the job. getch gets a character from console but does not echo to the screen
 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
Originally posted by: HJB417
I think you might need to use conio.h, I've never used the library before but quickly looking at the functions names, I think getch might do the job. getch gets a character from console but does not echo to the screen


Correct!!
:)
 

HJB417

Senior member
Dec 31, 2000
763
0
0
have it loop getch until it recieves 13 which is what pressing "Enter" returns. And whenever it doesn't return a 13, output a * or something, if you want, to show that the user it entering the password.
 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
Originally posted by: HJB417
well, the ASCII code returned when you press "Enter" is 13

0x0D

Depends on how many fingers you use to couint with

;)
 

thatbox

Senior member
Dec 5, 2002
253
0
76
Youd have to use character arrays and a do...while (to make it stop once enter is, er, entered) with getch(). And although I don't know much about it, theres also a getchar() that uses a different library file, but I dont remember it. How can you not love working with character arrays!?