Solved

passwd routine

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Show shut-down message as Windows 8 shuts down. 9 74
Windows Drag & Drop Location 2 85
wordcount challenge 11 78
Sed question 2 49
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

747 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

9 Experts available now in Live!

Get 1:1 Help Now