Solved

libc function?

Posted on 2002-05-25
2
292 Views
Last Modified: 2010-04-21
Hi everyone, i'm writing an application and at some point the program asks the user for a password. Now, i'd like to do this the same way that, say, GPG does: i type the password but the text doesn't show in the screen.

also i don't want (if possible) to use ncurses.

someone told me that there is a function for unechoed input in libc, any ideas?

thanks, any help will be really appreciated

uri
0
Comment
Question by:urif
2 Comments
 
LVL 1

Accepted Solution

by:
websolution earned 150 total points
ID: 7035059
I look for a "unechoed" and I couldn't find it neither in Posix nor Linux

using posix commands only:

#include <stdlib.h>
#include <stdio.h>

#include <termios.h>
#include <string.h>

static struct termios stored;

void echo_off(void)
{
    struct termios new;
    tcgetattr(0,&stored);
    memcpy(&new, &stored, sizeof(struct termios));
    new.c_lflag &= (~ECHO);
    tcsetattr(0,TCSANOW,&new);
    return;
}

void echo_on(void)
{
    tcsetattr(0,TCSANOW,&stored);
    return;
}

int main(int argc, char **argv)
{
    char passwd[256], login[256];
    printf("Enter your login: ");
    gets(login);
    printf("Enter your password: ");
    echo_off();
    gets(passwd);
    echo_on();
    printf("you entered: \n\tlogin: %s\n\tpassword: %s\n", login, passwd);
}

to compile it:  cc prog.c -o prog


using curses or ncurses
#include <curses.h>

main()
{
        char passwd[256], login[256];

        initscr();
        cbreak();
        echo();

        printw("enter your login: ");
        getstr(login);

        noecho();
        printw("enter your password: ");
        getstr(passwd);

        printw("you entered: \n\tlogin: %s\n\tpassword: %s\n", login, passwd);

        printw("Press a key to quit");
        getch();
        endwin();
}
to compile it:
cc -lcurses prog.c -o prog
or
cc -lncurses prog.c -o prog
0
 

Author Comment

by:urif
ID: 7035060
thx!
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now