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.

Comments

  • Hi!

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

    For example:
    [code]
    #include
    #include

    int main()
    {
    char *pass;

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

    printf("
    The password you entered:%s
    ",pass);

    return 0;
    }
    [/code]
    IMPORTANT!!

    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!

    Gabe
Sign In or Register to comment.

Howdy, Stranger!

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

Categories

In this Discussion