Skip to content

Commit

Permalink
fixes #22 - do not echo two-factor authentication password
Browse files Browse the repository at this point in the history
  • Loading branch information
d99kris committed Feb 19, 2020
1 parent 0a7f646 commit a40b189
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/nchat.1
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/telegram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<td::td_api::checkAuthenticationPassword>(password),
CreateAuthQueryHandler());
}
Expand Down
21 changes: 21 additions & 0 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
Expand Down Expand Up @@ -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;
}
1 change: 1 addition & 0 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit a40b189

Please sign in to comment.