#include
#include
#include
#include
using namespace std;
bool setEcho(int fd,bool option)
{
int err;
struct termios term;
if(tcgetattr(fd,&term)==-1)
{
cout <
return false;
}
if(option)
{
term.c_lflag|=ECHO;
}
else
{
term.c_lflag &=~ECHO;
}
err=tcsetattr(fd,TCSAFLUSH,&term);
if(err==-1 && err== EINTR)
{
cout <
return false;
}
return true;
}
string inputPassword(bool repeat)
{
string ret;
char buf[256];
//关回显
setEcho(STDIN_FILENO,false);
while(true)
{
cout<
cin.getline(buf,256);
buf[255]='\\0';
ret=buf;
if(repeat)
{
cout<
cin.getline(buf,256);
buf[255]='\\0';
if(ret==buf)break;
else cout<
}
else break;
}
//开回显
setEcho(STDIN_FILENO,true);
return ret;
}
int main(){
inputPassword(true);
}