diff --git a/CMakeLists.txt b/CMakeLists.txt index 0c2f52af..d6a96330 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ # Project cmake_minimum_required(VERSION 3.1 FATAL_ERROR) -project(nchat VERSION 0.25 LANGUAGES CXX) +project(nchat VERSION 0.26 LANGUAGES CXX) set(CMAKE_CXX_STANDARD 14) # Paths diff --git a/src/nchat.1 b/src/nchat.1 index 3a12a2a5..bbfc9b1e 100644 --- a/src/nchat.1 +++ b/src/nchat.1 @@ -1,5 +1,5 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.47.8. -.TH NCHAT "1" "November 2019" "nchat v0.25" "User Commands" +.TH NCHAT "1" "February 2020" "nchat v0.26" "User Commands" .SH NAME nchat \- ncurses chat .SH SYNOPSIS diff --git a/src/telegram.cpp b/src/telegram.cpp index 13eef894..30e1de7d 100644 --- a/src/telegram.cpp +++ b/src/telegram.cpp @@ -569,8 +569,7 @@ void Telegram::OnAuthStateUpdate() if (m_IsSetup) { std::cout << "Enter authentication password: "; - std::string password; - std::getline(std::cin, password); + std::string password = Util::GetPass(); SendQuery(td::td_api::make_object(password), CreateAuthQueryHandler()); } diff --git a/src/util.cpp b/src/util.cpp index 63960dc4..bf850654 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -530,3 +531,23 @@ void Util::CleanupStdErrRedirect() close(m_OrgStdErr); } } + +std::string Util::GetPass() +{ + std::string pass; + struct termios told, tnew; + + if (tcgetattr(STDIN_FILENO, &told) == 0) + { + memcpy(&tnew, &told, sizeof(struct termios)); + tnew.c_lflag &= ~ECHO; + if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &tnew) == 0) + { + std::getline(std::cin, pass); + tcsetattr(STDIN_FILENO, TCSAFLUSH, &told); + std::cout << std::endl; + } + } + + return pass; +} diff --git a/src/util.h b/src/util.h index aa72776e..5a222099 100644 --- a/src/util.h +++ b/src/util.h @@ -34,6 +34,7 @@ class Util static std::string BacktraceSymbolsStr(void* p_Callstack[], int p_Size); static void InitStdErrRedirect(const std::string& p_Path); static void CleanupStdErrRedirect(); + static std::string GetPass(); private: static std::string m_ConfigDir;