How to hide password characers from screen

Status
Not open for further replies.

Shikher_neo

Broken In
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

Commander in Chief
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)
 
Last edited:
Status
Not open for further replies.
Top Bottom