Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

passwd routine

Posted on 1997-02-01
1
Medium Priority
?
269 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
[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
1 Comment
 
LVL 1

Accepted Solution

by:
ian010997 earned 100 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

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

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

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

688 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