Browse Source

Don't echo passwords.

cl-refactor
Gav Wood 10 years ago
parent
commit
4011d4de71
  1. 11
      eth/main.cpp
  2. 14
      libdevcore/CommonIO.cpp
  3. 2
      libdevcore/CommonIO.h

11
eth/main.cpp

@ -1093,8 +1093,7 @@ int main(int argc, char** argv)
{ {
while (masterPassword.empty()) while (masterPassword.empty())
{ {
cout << "Please enter your MASTER password:" << flush; masterPassword = getPassword("Please enter your MASTER password: ");
getline(cin, masterPassword);
if (!keyManager.load(masterPassword)) if (!keyManager.load(masterPassword))
{ {
cout << "Password invalid. Try again." << endl; cout << "Password invalid. Try again." << endl;
@ -1106,10 +1105,8 @@ int main(int argc, char** argv)
{ {
while (masterPassword.empty()) while (masterPassword.empty())
{ {
cout << "Please enter a MASTER password to protect your key store. Make it strong." << flush; masterPassword = getPassword("Please enter a MASTER password to protect your key store (make it strong!): ");
getline(cin, masterPassword); string confirm = getPassword("Please confirm the password by entering it again: ");
string confirm;
cout << "Please confirm the password by entering it again." << flush;
getline(cin, confirm); getline(cin, confirm);
if (masterPassword != confirm) if (masterPassword != confirm)
{ {
@ -1126,7 +1123,7 @@ int main(int argc, char** argv)
g_logPost = [&](std::string const& a, char const*) { if (silence) logbuf += a + "\n"; else cout << "\r \r" << a << endl << additional << flush; }; g_logPost = [&](std::string const& a, char const*) { if (silence) logbuf += a + "\n"; else cout << "\r \r" << a << endl << additional << flush; };
// TODO: give hints &c. // TODO: give hints &c.
auto getPassword = [&](Address const& a){ auto s = silence; silence = true; string ret; cout << endl << "Enter password for address " << a.abridged() << ": " << flush; std::getline(cin, ret); silence = s; return ret; }; auto getPassword = [&](Address const& a){ auto s = silence; silence = true; cout << endl; string ret = dev::getPassword("Enter password for address " + a.abridged() + ": "); silence = s; return ret; };
#if ETH_JSONRPC || !ETH_TRUE #if ETH_JSONRPC || !ETH_TRUE
shared_ptr<WebThreeStubServer> jsonrpcServer; shared_ptr<WebThreeStubServer> jsonrpcServer;

14
libdevcore/CommonIO.cpp

@ -20,7 +20,8 @@
*/ */
#include "CommonIO.h" #include "CommonIO.h"
#include <iostream>
#include <cstdlib>
#include <fstream> #include <fstream>
#include "Exceptions.h" #include "Exceptions.h"
using namespace std; using namespace std;
@ -117,3 +118,14 @@ void dev::writeFile(std::string const& _file, bytesConstRef _data)
ofstream(_file, ios::trunc|ios::binary).write((char const*)_data.data(), _data.size()); ofstream(_file, ios::trunc|ios::binary).write((char const*)_data.data(), _data.size());
} }
std::string dev::getPassword(std::string const& _prompt)
{
#if WIN32
cout << _prompt << flush;
std::string ret;
std::getline(cin, ret);
return ret;
#else
return getpass(_prompt.c_str());
#endif
}

2
libdevcore/CommonIO.h

@ -42,6 +42,8 @@
namespace dev namespace dev
{ {
std::string getPassword(std::string const& _prompt);
/// Retrieve and returns the contents of the given file. If the file doesn't exist or isn't readable, returns an empty bytes. /// Retrieve and returns the contents of the given file. If the file doesn't exist or isn't readable, returns an empty bytes.
bytes contents(std::string const& _file); bytes contents(std::string const& _file);
std::string contentsString(std::string const& _file); std::string contentsString(std::string const& _file);

Loading…
Cancel
Save