Hide characters as you type for password program - VxWorks

This is a discussion on Hide characters as you type for password program - VxWorks ; Hi all, I am trying to run the following code for hiding the characters as typed for a password. The code works in the Linux environment, but when I port it over to VXworks the characters are echoed to the ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: Hide characters as you type for password program

  1. Hide characters as you type for password program

    Hi all,

    I am trying to run the following code for hiding the characters as
    typed for a password.

    The code works in the Linux environment, but when I port it over to
    VXworks the characters are echoed to the screen and when a new line is
    typed it prints the "*".

    Any help would be greatly appreciated!

    -Rusty

    Code is as follows:

    #include
    #include

    int main(int argc, char **argv)
    {
    struct termio tty, oldtty;

    //Save the old tty settings and get rid of echo for new tty

    ioctl(0, TCGETA, &oldtty);
    tty = oldtty;
    tty.c_lflag &= ~(ICANON|ECHO|ECHOE|ECHOK|ECHONL);
    tty.c_cc[VMIN] = 1;
    tty.c_cc[VTIME] = 0;
    ioctl(0, TCSETA, &tty);

    printf("Please enter the Password\n");

    while (c != '\n')
    {
    c = getchar();

    if (c == '\n')
    {
    printf("\n");
    break;
    }

    strncat(temp1, &c, 1);
    printf("*");
    }

    //reset the old settings

    ioctl(0, TCSETA, &oldtty);
    }


  2. Re: Hide characters as you type for password program

    Hi Rusty,

    I don't have any vxWorks manuals handy at the moment, but maybe I can
    point out a few issues anyway.

    Rusty wrote:
    > Hi all,


    > I am trying to run the following code for hiding the characters as
    > typed for a password.


    > The code works in the Linux environment, but when I port it over to
    > VXworks the characters are echoed to the screen and when a new line is
    > typed it prints the "*".


    This sounds like whatever is reading the input, it is operating in line rather
    than character mode. You didn't mention how the user connects to the system.
    Telnet, for example, has its own set of options that may be misconfigured to
    cause the reported results.

    > Any help would be greatly appreciated!


    > -Rusty


    > Code is as follows:


    > #include
    > #include


    I didn't think that vxWorks shipped with termio, although I could be
    mistaken, lack of documentation and all. You also didn't name a vxWorks
    version, although the main() below leads me to believe this is an RTP
    application, making it a 6.x release.

    > int main(int argc, char **argv)
    > {
    > struct termio tty, oldtty;


    > //Save the old tty settings and get rid of echo for new tty


    > ioctl(0, TCGETA, &oldtty);
    > tty = oldtty;
    > tty.c_lflag &= ~(ICANON|ECHO|ECHOE|ECHOK|ECHONL);
    > tty.c_cc[VMIN] = 1;
    > tty.c_cc[VTIME] = 0;
    > ioctl(0, TCSETA, &tty);


    Your code doesn't check the return value of ioctl(). It may not be succeeding,
    and if not, it may be setting an informative errno such as EINVAL.
    The same goes for the first and third calls to ioctl(), creating the
    potential for either of the set operations (if they succeed) to toggle
    flags at random.

    > printf("Please enter the Password\n");


    > while (c != '\n')


    > {
    > c = getchar();


    > if (c == '\n')
    > {
    > printf("\n");
    > break;
    > }


    > strncat(temp1, &c, 1);
    > printf("*");


    Once the character echo issue is resolved, it may be worth considering
    following this with an fflush(), or using an API with less buffering involved.

    > }


    > //reset the old settings


    > ioctl(0, TCSETA, &oldtty);
    > }



  3. Re: Hide characters as you type for password program

    try converting your I/O port into RAW mode.
    you are getting only one '*' in the end because it is in line mode and
    until u will not press enter key your getchar function will not reurn.


  4. Re: Hide characters as you type for password program

    Alok,

    I thought the default mode is RAW. I tried using ioctl with the
    OPT_LINE option, this did not work. How can I port into RAW mode?

    alok ha escrito:

    > try converting your I/O port into RAW mode.
    > you are getting only one '*' in the end because it is in line mode and
    > until u will not press enter key your getchar function will not reurn.



+ Reply to Thread