Solved

libc function?

Posted on 2002-05-25
2
317 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

690 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