[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

libc function?

Posted on 2002-05-25
2
Medium Priority
?
332 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 600 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
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…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

656 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