DIGIT-ARC read-only archive · snapshot: July 23, 2026

How to hide password characers from screen

2 posts · originally from https://geek.digit.in/community/threads/how-to-hide-password-characers-from-screen.72791/

Shikher_neo
Shikher_neo Original post #1
Nov 9, 2007 at 1:41 AM
Hey guys i have a problem,
how do i hide the characters and replace them with a * or # so they cant be read in the c++ console program?
please help me out
QwertyManiac
Nov 9, 2007 at 7:01 AM
The easiest solution would be to use a non echoing input like getch() (In conio.h or curses.h [Non standard])

Something like:
Code:
#include<stdio.h>

int main()
{
    char a[10], c;
    int i=0;
    c = ' ';
    printf("Enter the password: ");
    while (c != 13)
    {
        c = (char)getch();
        a[i] = c;
        printf("*");
        i++;
    }
    printf("\nPassword was: %s\n",a);
    return 0;
}

I don't know of a standard function that does the same. Someone else here might.

In Python (If anyone's interested), getting a password is as easy as:
Code:
import getpass
pswd = getpass.getpass("Enter Password: ")
print pswd
(All it does is hide input [Again, non echo], Unix style)