Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


hiding password input

how can I hide, or mask with asterisks, the user input to a C program, such as an input password?
I want to collect the user input, but not have it visable on the terminal screen.


  • GabeGabe Member Posts: 61

    I think you should use the [italic]char *getpass(const char *prompt);[/italic] function defined in [italic]unistd.h[/italic].

    For example:

    int main()
    char *pass;

    pass=getpass("Enter your password:");

    The password you entered:%s

    return 0;

    This function returns a pointer to it's own allocated memory. So you MUST copy the string into an another memory area otherwise the next call to [italic]getpass[/italic] will destroy the previos value!

Sign In or Register to comment.