fast_io icon indicating copy to clipboard operation
fast_io copied to clipboard

How to scan password?

Open UMU618 opened this issue 3 years ago • 4 comments

If I use scan to receive a password, it'll echo on console.

UMU618 avatar Jul 11 '22 16:07 UMU618

void EnableStdinEcho(bool enable) noexcept {
#ifdef WIN32
  HANDLE std_in = GetStdHandle(STD_INPUT_HANDLE);
  DWORD mode = 0;
  GetConsoleMode(std_in, &mode);
  if (enable) {
    mode |= ENABLE_ECHO_INPUT;
  } else {
    mode &= ~ENABLE_ECHO_INPUT;
  }
  SetConsoleMode(std_in, mode);
#else
  struct termios tty;
  tcgetattr(STDIN_FILENO, &tty);
  if (enable) {
    tty.c_lflag |= ECHO;
  } else {
    tty.c_lflag &= ~ECHO;
  }
  (void)tcsetattr(STDIN_FILENO, TCSANOW, &tty);
#endif
}

UMU618 avatar Jul 18 '22 09:07 UMU618

#ifdef _WIN32 #include <windows.h> #else #include <termios.h> #include <unistd.h> #endif

UMU618 avatar Jul 18 '22 09:07 UMU618

看样这个功能可以考虑加到fast_io中

trcrsired avatar Jul 20 '22 15:07 trcrsired

大神英明啊,有个专门输入密码的包装更方便使用。

UMU618 avatar Jul 21 '22 17:07 UMU618