mirror of
https://codeberg.org/anoncontributorxmr/monero.git
synced 2024-11-10 13:13:27 +01:00
add --password-file option
This commit is contained in:
parent
10cc6a8593
commit
302cc9c700
@ -37,6 +37,7 @@
|
|||||||
#include <thread>
|
#include <thread>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <fstream>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <boost/lexical_cast.hpp>
|
#include <boost/lexical_cast.hpp>
|
||||||
#include <boost/program_options.hpp>
|
#include <boost/program_options.hpp>
|
||||||
@ -84,6 +85,7 @@ namespace
|
|||||||
const command_line::arg_descriptor<std::string> arg_daemon_address = {"daemon-address", sw::tr("Use daemon instance at <host>:<port>"), ""};
|
const command_line::arg_descriptor<std::string> arg_daemon_address = {"daemon-address", sw::tr("Use daemon instance at <host>:<port>"), ""};
|
||||||
const command_line::arg_descriptor<std::string> arg_daemon_host = {"daemon-host", sw::tr("Use daemon instance at host <arg> instead of localhost"), ""};
|
const command_line::arg_descriptor<std::string> arg_daemon_host = {"daemon-host", sw::tr("Use daemon instance at host <arg> instead of localhost"), ""};
|
||||||
const command_line::arg_descriptor<std::string> arg_password = {"password", sw::tr("Wallet password"), "", true};
|
const command_line::arg_descriptor<std::string> arg_password = {"password", sw::tr("Wallet password"), "", true};
|
||||||
|
const command_line::arg_descriptor<std::string> arg_password_file = {"password-file", sw::tr("Wallet password file"), "", true};
|
||||||
const command_line::arg_descriptor<std::string> arg_electrum_seed = {"electrum-seed", sw::tr("Specify Electrum seed for wallet recovery/creation"), ""};
|
const command_line::arg_descriptor<std::string> arg_electrum_seed = {"electrum-seed", sw::tr("Specify Electrum seed for wallet recovery/creation"), ""};
|
||||||
const command_line::arg_descriptor<bool> arg_restore_deterministic_wallet = {"restore-deterministic-wallet", sw::tr("Recover wallet using Electrum-style mnemonic seed"), false};
|
const command_line::arg_descriptor<bool> arg_restore_deterministic_wallet = {"restore-deterministic-wallet", sw::tr("Recover wallet using Electrum-style mnemonic seed"), false};
|
||||||
const command_line::arg_descriptor<bool> arg_non_deterministic = {"non-deterministic", sw::tr("Create non-deterministic view and spend keys"), false};
|
const command_line::arg_descriptor<bool> arg_non_deterministic = {"non-deterministic", sw::tr("Create non-deterministic view and spend keys"), false};
|
||||||
@ -793,11 +795,27 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm)
|
|||||||
if (m_daemon_address.empty())
|
if (m_daemon_address.empty())
|
||||||
m_daemon_address = std::string("http://") + m_daemon_host + ":" + std::to_string(m_daemon_port);
|
m_daemon_address = std::string("http://") + m_daemon_host + ":" + std::to_string(m_daemon_port);
|
||||||
|
|
||||||
|
if (has_arg(vm, arg_password) && has_arg(vm, arg_password_file))
|
||||||
|
{
|
||||||
|
fail_msg_writer() << tr("can't specify more than one of --password and --password-file");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
tools::password_container pwd_container;
|
tools::password_container pwd_container;
|
||||||
if (command_line::has_arg(vm, arg_password))
|
if (command_line::has_arg(vm, arg_password))
|
||||||
{
|
{
|
||||||
pwd_container.password(command_line::get_arg(vm, arg_password));
|
pwd_container.password(command_line::get_arg(vm, arg_password));
|
||||||
}
|
}
|
||||||
|
else if (command_line::has_arg(vm, arg_password_file))
|
||||||
|
{
|
||||||
|
std::ifstream pfs(command_line::get_arg(vm, arg_password_file));
|
||||||
|
std::string password((std::istreambuf_iterator<char>(pfs)),
|
||||||
|
(std::istreambuf_iterator<char>()));
|
||||||
|
// Remove line breaks the user might have inserted
|
||||||
|
password.erase(std::remove(password.begin(), password.end(), '\r'), password.end());
|
||||||
|
password.erase(std::remove(password.begin(), password.end(), '\n'), password.end());
|
||||||
|
pwd_container.password(password.c_str());
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
bool r = pwd_container.read_password();
|
bool r = pwd_container.read_password();
|
||||||
@ -2418,6 +2436,7 @@ int main(int argc, char* argv[])
|
|||||||
command_line::add_arg(desc_params, arg_generate_new_wallet);
|
command_line::add_arg(desc_params, arg_generate_new_wallet);
|
||||||
command_line::add_arg(desc_params, arg_generate_from_view_key);
|
command_line::add_arg(desc_params, arg_generate_from_view_key);
|
||||||
command_line::add_arg(desc_params, arg_password);
|
command_line::add_arg(desc_params, arg_password);
|
||||||
|
command_line::add_arg(desc_params, arg_password_file);
|
||||||
command_line::add_arg(desc_params, arg_daemon_address);
|
command_line::add_arg(desc_params, arg_daemon_address);
|
||||||
command_line::add_arg(desc_params, arg_daemon_host);
|
command_line::add_arg(desc_params, arg_daemon_host);
|
||||||
command_line::add_arg(desc_params, arg_daemon_port);
|
command_line::add_arg(desc_params, arg_daemon_port);
|
||||||
|
Loading…
Reference in New Issue
Block a user