/******************************************************************************* * libretroshare/src/retroshare/util/rskbdinput.cc * * * * Copyright (C) 2019 Cyril Soler * * * * This program is free software: you can redistribute it and/or modify * * it under the terms of the GNU Lesser General Public License as * * published by the Free Software Foundation, either version 3 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public License * * along with this program. If not, see . * * * *******************************************************************************/ #ifndef __ANDROID__ #include #include #ifdef WINDOWS_SYS #include #include #define PASS_MAX 512 namespace RsUtil { std::string rs_getpass(const std::string& prompt,bool no_echo) { static char getpassbuf [PASS_MAX + 1]; size_t i = 0; int c; if (!prompt.empty()) { std::cerr << prompt ; std::cerr.flush(); } for (;;) { c = _getch (); if (c == '\r') { getpassbuf [i] = '\0'; break; } else if (i < PASS_MAX) { getpassbuf[i++] = c; } if (i >= PASS_MAX) { getpassbuf [i] = '\0'; break; } } if (!prompt.empty()) { std::cerr << "\r\n" ; std::cerr.flush(); } return std::string(getpassbuf); } } #else #include #include #include #include #include static int getch() { int ch; struct termios t_old, t_new; tcgetattr(STDIN_FILENO, &t_old); t_new = t_old; t_new.c_lflag &= ~(ICANON | ECHO); tcsetattr(STDIN_FILENO, TCSANOW, &t_new); ch = getchar(); tcsetattr(STDIN_FILENO, TCSANOW, &t_old); return ch; } namespace RsUtil { std::string rs_getpass(const std::string& prompt, bool no_echo) { const char BACKSPACE=127; const char RETURN=10; std::string password; unsigned char ch=0; std::cout <