f



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

I tried a google search for 'c program accept password' and there were a number of examples given but they all used conio.h, which xcode couldn't find and hence the build failed.

I also tried the documentation (search for 'c terminal program accept password') in Help in Xcode itself and of course that was, <Flame on>
like all current Mac software documentation (I exaggerate, but willingly)
totally useless - things on the MAC have got to the point of self-immolating
complexity - self-immolating because there is no attempt to ORGANIZE the information in any way that a normal person would even want to attempt to
understand. <Flame off>

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?

This is OS X (10.7) and again intended for a MAC terminal application.

Thanks for any help, and apologies if the flame offended or irritated anyone.

Regards,

Ken Quirici
0
kquirici
6/9/2012 2:22:27 PM
comp.sys.mac.programmer.help 4653 articles. 2 followers. Post Follow

3 Replies
499 Views

Similar Articles

[PageSpeed] 35

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?
>
> This is OS X (10.7) and again intended for a MAC terminal
> application.
>
> Thanks for any help, and apologies if the flame offended or
> irritated anyone.
>
> Regards,
>
> Ken Quirici

getpass(3) doesn't work?
0
Stefan
6/9/2012 4:31:50 PM
In article 
<30b90328-0194-4cfa-aac9-7d2ffcb336e0@googlegroups.com>,
 "kquirici@yahoo.com" <kquirici@yahoo.com> wrote:

> I tried a google search for 'c program accept password' and there were a 
> number of examples given but they all used conio.h, which xcode couldn't find 
> and hence the build failed.
> 
> I also tried the documentation (search for 'c terminal program accept 
> password') in Help in Xcode itself and of course that was, <Flame on>
> like all current Mac software documentation (I exaggerate, but willingly)
> totally useless - things on the MAC have got to the point of self-immolating
> complexity - self-immolating because there is no attempt to ORGANIZE the 
> information in any way that a normal person would even want to attempt to
> understand. <Flame off>
> 
> 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?
> 
> This is OS X (10.7) and again intended for a MAC terminal application.
> 
> Thanks for any help, and apologies if the flame offended or irritated anyone.
> 
> Regards,
> 
> Ken Quirici

if for some reason getpass() doesn't work, there is 
readpassphrase(), and then you can always use ioctl() in 
conjunction with the information from man 4 tty and man 4 termios, 
although the later may or may not be sufficiently generic for all 
systems.

However, most Unix systems have an stty command, so I guess you 
could use system("stty -echo"); before asking for the password, 
and then system("stty echo"); after getting the password.

As with any portable code, you will need to test on all ported 
platforms to insure your password code works as expected.
0
Bob
6/10/2012 3:09:10 AM
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
0
Wayne
6/12/2012 11:46:55 PM
Reply: