Enter the password string echo * number

Source: Internet
Author: User


#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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.