From dd57080f250aa48fd3e6378fad6436d7ec16afc4 Mon Sep 17 00:00:00 2001 From: woodser Date: Sun, 30 Jan 2022 10:02:52 -0500 Subject: [PATCH] support changing wallet password --- src/wallet/monero_wallet.h | 18 ++++++++++++++---- src/wallet/monero_wallet_full.cpp | 18 +++++++++++++----- src/wallet/monero_wallet_full.h | 3 ++- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/src/wallet/monero_wallet.h b/src/wallet/monero_wallet.h index 490de78..eac77cc 100644 --- a/src/wallet/monero_wallet.h +++ b/src/wallet/monero_wallet.h @@ -1328,10 +1328,13 @@ namespace monero { } /** - * Save the wallet at its current path. + * Change the wallet password. + * + * @param old_password is the wallet's old password + * @param new_password is the wallet's new password */ - virtual void save() { - throw std::runtime_error("save() not supported"); + virtual void change_password(const std::string& old_password, const std::string& new_password) { + throw std::runtime_error("change_password() not supported"); } /** @@ -1340,10 +1343,17 @@ namespace monero { * @param path is the new wallet's path * @param password is the new wallet's password */ - virtual void move_to(std::string path, std::string password) { + virtual void move_to(const std::string& path, const std::string& password) { throw std::runtime_error("move_to() not supported"); } + /** + * Save the wallet at its current path. + */ + virtual void save() { + throw std::runtime_error("save() not supported"); + } + /** * Optionally save then close the wallet. * diff --git a/src/wallet/monero_wallet_full.cpp b/src/wallet/monero_wallet_full.cpp index 82755a4..a317cb7 100644 --- a/src/wallet/monero_wallet_full.cpp +++ b/src/wallet/monero_wallet_full.cpp @@ -3312,16 +3312,24 @@ namespace monero { return tx_hashes; } + void monero_wallet_full::change_password(const std::string& old_password, const std::string& new_password) { + MTRACE("change_password(" << "***" << ", ***)"); + #if !defined(__EMSCRIPTEN__) // TODO: wallet2 verify_password loads from disk so password is verified in js for wasm + if (!m_w2->verify_password(old_password)) throw std::runtime_error("Invalid original password."); + #endif + m_w2->change_password(m_w2->get_wallet_file(), old_password, new_password); + } + + void monero_wallet_full::move_to(const std::string& path, const std::string& password) { + MTRACE("move_to(" << path << ", ***)"); + m_w2->store_to(path, password); + } + void monero_wallet_full::save() { MTRACE("save()"); m_w2->store(); } - void monero_wallet_full::move_to(std::string path, std::string password) { - MTRACE("move_to(" << path << ", ***)"); - m_w2->store_to(path, password); - } - std::string monero_wallet_full::get_keys_file_buffer(const epee::wipeable_string& password, bool view_only) const { boost::optional keys_file_data = m_w2->get_keys_file_data(password, view_only); std::string buf; diff --git a/src/wallet/monero_wallet_full.h b/src/wallet/monero_wallet_full.h index 0e569e9..ee690d1 100644 --- a/src/wallet/monero_wallet_full.h +++ b/src/wallet/monero_wallet_full.h @@ -274,8 +274,9 @@ namespace monero { int import_multisig_hex(const std::vector& multisig_hexes) override; monero_multisig_sign_result sign_multisig_tx_hex(const std::string& multisig_tx_hex) override; std::vector submit_multisig_tx_hex(const std::string& signed_multisig_tx_hex) override; + void change_password(const std::string& old_password, const std::string& new_password) override; + void move_to(const std::string& path, const std::string& password) override; void save() override; - void move_to(std::string path, std::string password) override; void close(bool save = false) override; /**