diff options
author | Jethro Grassie <jtg@xtrabass.com> | 2018-02-01 15:32:30 -0500 |
---|---|---|
committer | Jethro Grassie <jtg@xtrabass.com> | 2018-02-10 18:29:49 -0500 |
commit | a4b50a6f511e60a57955dab7586aba08a5c54337 (patch) | |
tree | 93a0915795456aae2eab1984d07929e8c4c12cd3 /src/common/password.cpp | |
parent | Merge pull request #3198 (diff) | |
download | monero-a4b50a6f511e60a57955dab7586aba08a5c54337.tar.xz |
handle ^D and ^C while password prompting
Diffstat (limited to 'src/common/password.cpp')
-rw-r--r-- | src/common/password.cpp | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/common/password.cpp b/src/common/password.cpp index ef026c979..9336a14fc 100644 --- a/src/common/password.cpp +++ b/src/common/password.cpp @@ -42,12 +42,10 @@ #include <unistd.h> #endif -#ifdef HAVE_READLINE - #include "readline_buffer.h" -#endif - #include "memwipe.h" +#define EOT 0x4 + namespace { #if defined(_WIN32) @@ -134,7 +132,7 @@ namespace while (aPass.size() < tools::password_container::max_password_size) { int ch = getch(); - if (EOF == ch) + if (EOF == ch || ch == EOT) { return false; } @@ -229,13 +227,20 @@ namespace tools m_password.clear(); } + std::atomic<bool> password_container::is_prompting(false); + boost::optional<password_container> password_container::prompt(const bool verify, const char *message) { + is_prompting = true; password_container pass1{}; password_container pass2{}; if (is_cin_tty() ? read_from_tty(verify, message, pass1.m_password, pass2.m_password) : read_from_file(pass1.m_password)) + { + is_prompting = false; return {std::move(pass1)}; + } + is_prompting = false; return boost::none; } |