Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.sys.mac.programmer.help > #129

Re: I'm trying to write a program that accepts an invisible password typed in....

From Wayne Salamon <xenon@net.invalid>
Newsgroups comp.sys.mac.programmer.help
Subject Re: I'm trying to write a program that accepts an invisible password typed in....
Date 2012-06-12 23:46 +0000
Organization Nomalas
Message-ID <slrnjtfl9c.f4b.xenon@tomservo.wsalamon.net> (permalink)
References <30b90328-0194-4cfa-aac9-7d2ffcb336e0@googlegroups.com>

Show all headers | View raw


On 2012-06-09, kquirici@yahoo.com <kquirici@yahoo.com> wrote:
>
> Does anyone thru personal experience know of a sample C program for a terminal
> application that will accept an invisible or masked password typed in?

If getpass(3) doesn't work for you, here's a function I use
in a project to get a PIN of a maximum length:

/*
 * getPin() is adapted from the comp.unix.programmer FAQ, which
 * adapted from Stevens' Advanced Programming In The Unix Environment.
 */
static int
getPin(char *pin)
{
        int i;
        sigset_t sig, sigsave;
        struct termios term, termsave;
        FILE *fp;
        int c;

        if((fp=fopen(ctermid(NULL),"r+")) == NULL)
                return (-1);
        setbuf(fp, NULL);

        /* block SIGINT & SIGTSTP, save signal mask */
        sigemptyset(&sig);
        sigaddset(&sig, SIGINT);
        sigaddset(&sig, SIGTSTP);
        sigprocmask(SIG_BLOCK, &sig, &sigsave);

        tcgetattr(fileno(fp), &termsave);
        term = termsave;
        term.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL);
        tcsetattr(fileno(fp), TCSAFLUSH, &term);
        fputs("PIN: ", fp);
        for (i = 0; i < PIN_LENGTH; i++) {
                c = getc(fp);
                if ((c != EOF) && (c != '\n'))
                        pin[i] = c;
                else
                        break;
        }
        tcsetattr(fileno(fp), TCSAFLUSH, &termsave);
        sigprocmask(SIG_SETMASK, &sigsave, NULL);
        fclose(fp);
        return(0);
}

You can see from the comment where I started. This function
works on OS-X/Linux/FreeBSD, but I haven't run it for a while
on OS-X (10.5 was probably the last version I tried).

-- 
Wayne Salamon

Back to comp.sys.mac.programmer.help | Previous | NextPrevious in thread | Find similar


Thread

I'm trying to write a program that accepts an invisible password typed in.... "kquirici@yahoo.com" <kquirici@yahoo.com> - 2012-06-09 07:22 -0700
  Re: I'm trying to write a program that accepts an invisible password typed in.... Stefan Krueger <stadtkind2@gmx.de> - 2012-06-09 16:31 +0000
  Re: I'm trying to write a program that accepts an invisible password typed in.... Bob Harris <nospam.News.Bob@remove.Smith-Harris.us> - 2012-06-09 23:09 -0400
  Re: I'm trying to write a program that accepts an invisible password typed in.... Wayne Salamon <xenon@net.invalid> - 2012-06-12 23:46 +0000

csiph-web