From ad4649ac81f4539e87b17eb7907e0553c7e11098 Mon Sep 17 00:00:00 2001 From: m2049r <30435443+m2049r@users.noreply.github.com> Date: Wed, 2 Aug 2017 00:41:05 +0200 Subject: Enable verifying wallet password with having to load wallet. --- src/wallet/wallet2.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'src/wallet/wallet2.cpp') diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 6b1026a55..44cf33439 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -2095,6 +2095,7 @@ bool wallet2::load_keys(const std::string& keys_file_name, const std::string& pa /*! * \brief verify password for default wallet keys file. * \param password Password to verify + * \return true if password is correct * * for verification only * should not mutate state, unlike load_keys() @@ -2103,7 +2104,23 @@ bool wallet2::load_keys(const std::string& keys_file_name, const std::string& pa */ bool wallet2::verify_password(const std::string& password) const { - const std::string keys_file_name = m_keys_file; + return verify_password(m_keys_file, password, m_watch_only); +} + +/*! + * \brief verify password for specified wallet keys file. + * \param keys_file_name Keys file to verify password for + * \param password Password to verify + * \param watch_only If set = only verify view keys, otherwise also spend keys + * \return true if password is correct + * + * for verification only + * should not mutate state, unlike load_keys() + * can be used prior to rewriting wallet keys file, to ensure user has entered the correct password + * + */ +bool wallet2::verify_password(const std::string& keys_file_name, const std::string& password, bool watch_only) +{ wallet2::keys_file_data keys_file_data; std::string buf; bool r = epee::file_io_utils::load_file_to_string(keys_file_name, buf); @@ -2136,7 +2153,7 @@ bool wallet2::verify_password(const std::string& password) const const cryptonote::account_keys& keys = account_data_check.get_keys(); r = r && verify_keys(keys.m_view_secret_key, keys.m_account_address.m_view_public_key); - if(!m_watch_only) + if(!watch_only) r = r && verify_keys(keys.m_spend_secret_key, keys.m_account_address.m_spend_public_key); return r; } -- cgit v1.2.3