Solved

passwd routine

Posted on 1997-02-01
1
265 Views
Last Modified: 2013-12-26
how can i write a login/passwd prog in ANSI C in unix where
when the user type in the passwd, it is not echoed and the cursor doesn't even move? just like login on to a unix system? all i know is that termios.h must be included? thanx
0
Comment
Question by:wilddream
1 Comment
 
LVL 1

Accepted Solution

by:
ian010997 earned 50 total points
ID: 1292181
#define _POSIX_SOURCE 1

#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <termios.h>
#include <sys/types.h>
#include <sys/wait.h>


/*
 * Prototypes
 */

int getpswd(char *, unsigned);

/*************************************************************************/

int getpswd(char *buff, unsigned size)
{
struct termios attr;
int     n;

printf("Password: ");
fflush(stdout);
if(tcgetattr(STDIN_FILENO, &attr) != 0) return(-1);
attr.c_lflag &= ~(ECHO);
if(tcsetattr(STDIN_FILENO, TCSAFLUSH, &attr) != 0) return(-1);
n = read(STDIN_FILENO, buff, size);
attr.c_lflag |= ECHO;
if(tcsetattr(STDIN_FILENO, TCSANOW, &attr) != 0) return(-1);
printf("\n");
return(n);
} /* getpswd */

0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Include multiple hostnames in this command? 3 55
Error on moodle after upgrade 3 140
method notes when mouse over in eclipse 5 87
Authenticate using sesu from script 7 59
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

828 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