Solved

passwd routine

Posted on 1997-02-01
1
262 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
while loop over for loop 7 92
conditional code and condition difference 9 76
Doc'in system (example?) BA 7 86
matchUp  challenge 9 91
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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…
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.
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

929 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

15 Experts available now in Live!

Get 1:1 Help Now