#include <stdio.h>
#include <termios.h>
static struct Termios stored_settings;
static void set_keypress (void)
{
struct Termios new_settings;
Storing the old pattern
Tcgetattr (0,&stored_settings);
New_settings = stored_settings;
/* Disable canonical mode, and set buffer size to 1 byte */
New_settings.c_lflag &= (~icanon); Do not use standard mode, that is, cancel row buffering
New_settings.c_cc[vtime] = 0;
New_settings.c_cc[vmin] = 1;
New_settings.c_lflag &= ~echo;
Tcsetattr (0, Tcsanow, &new_settings);
Return
}
static void reset_keypress (void)
{
Tcsetattr (0,tcsanow,&stored_settings); Restore Old mode
Return
}
/** READPASSWD */
void readpasswd (char* buffer, int size)
{
char c;
int cnt = 0;
Set_keypress ();
while ((c = GetChar ()) = ' \ n ') {
Putchar (' * ');
buffer[cnt++] = c;
if (CNT >= size-1)
Break
}
Reset_keypress ();
BUFFER[CNT] = 0;
}
int main (int argc, char* argv[])
{
Char buffer[100];
READPASSWD (buffer, 100);
printf ("Input password:%s\n", buffer);
}
Enter the password string echo * number