Login on Linux is the input password will not be echoed, so I also wrote a simple login program, so that when entering the password is no longer echo.
#include <stdio.h>#include<stdlib.h>#include<termios.h>#include<unistd.h>#include<errno.h>#include<string.h>#include<stdbool.h>#defineUser_name "username"#defineUser_pass "Userpass"#defineMAX 20#defineEchoflags (ECHO | Echoe | Echok)intSet_disp_mode (intFdintoption) { interr; structTermios term; if(Tcgetattr (fd, &term) = =-1) {fprintf (stderr,"can\ ' t get the attribution of the terminal!\n"); Exit (1); } if(option) {Term.c_lflag|=Echoflags; } Else{Term.c_lflag&= ~Echoflags; } Err= Tcsetattr (FD, Tcsaflush, &term ); if(Err = =-1&& Err = =eintr) {fprintf (stderr,"can\ ' t set the attribution of the terminal!\n"); Exit (1); } return 0;}intGET_PASSWD (Char* passwd,intsize) { intC; intn =0; fprintf (stderr,"Please input password:"); Do{C=GetChar (); if(c! ='\ n'&& C! ='\ r') {Passwd[n++] =C; } } while(c! ='\ n'&& C! ='\ r'&& N < (size-1)); Passwd[n]=' /'; returnN;}BOOLCheck_login (Const Char* Name,Const Char*passwd) { intNlen =strlen (user_name); intPlen =strlen (User_pass); return(STRNCMP (name, user_name, nlen) = =0) &&(strncmp (passwd, User_pass, Plen)==0);}intMainvoid) { CharName[max]; CharPasswd[max]; login:fprintf (stderr,"Login User:"); Fgets (name, MAX, stdin); Name[strlen (name)-1] =' /'; Set_disp_mode (Stdin_fileno,0); GET_PASSWD (passwd, MAX); if(Check_login (name, passwd)) {fprintf (stderr,"\nhello%s, welcome!\n", name); } Else{fprintf (stderr,"\ n"); Set_disp_mode (Stdin_fileno,1); GotoLOGIN; } set_disp_mode (Stdin_fileno,1); return 0;}