LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 07-24-2004, 07:49 AM   #1
blackzone
Member
 
Registered: Jun 2004
Posts: 256

Rep: Reputation: 30
c related question.


how do I mask what a user type?

for example I have the following code:

char myPass[100];
printf("Input password: ");
scanf("%s"), myPass);

===============================
which will ask a user for an password. But I do not want the user's password to be seen when he typed on the screen. Prefer to mask it using "****" characters. How do I do that?
 
Old 07-24-2004, 08:55 AM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 108Reputation: 108
Re: c related question.

Code:
#include <stdio.h>
#include <stdlib.h>
#include <termios.h>

static struct termios oldt;

void restore_terminal_settings(void)
{
    tcsetattr(0, TCSANOW, &oldt);  /* Apply saved settings */
}

void disable_echo(void)
{
    struct termios newt;

    tcgetattr(0, &oldt);  /* Save terminal settings */
    newt = oldt;  /* Init new settings */
    newt.c_lflag &= ~ECHO;  /* Change settings */
    tcsetattr(0, TCSANOW, &newt);  /* Apply settings */
}


int main()
{
    char myPass[100];

    printf("Input password: ");

    disable_echo();
    scanf("%s", myPass);
    restore_terminal_settings();

    printf("\n");
    return 0;
}
For an explanation about how it works see this thread:
http://www.linuxquestions.org/questi...hreadid=208803
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Boot-related question. wombat53 Slackware 55 06-21-2005 12:37 PM
SNAT related question Menestrel Linux - Networking 1 01-13-2005 10:56 PM
DNS related question tusher Linux - Newbie 1 12-07-2003 01:03 PM
DNS related question tusher Linux - Networking 1 12-01-2003 09:15 AM
question - DNS related rewt Linux - General 2 09-14-2001 10:19 PM


All times are GMT -5. The time now is 01:02 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration