diff --git a/src/client/configurationmanager.cpp b/src/client/configurationmanager.cpp index 7216dde8b2779150fb1bcecf47e4bcc2937d2be6..382ca294658c143189c56c1cc66592a7dac77e59 100644 --- a/src/client/configurationmanager.cpp +++ b/src/client/configurationmanager.cpp @@ -251,6 +251,12 @@ sendRegister(const std::string& accountID, bool enable) jami::Manager::instance().sendRegister(accountID, enable); } +bool +isPasswordValid(const std::string& accountID, const std::string& password) +{ + return jami::Manager::instance().isPasswordValid(accountID, password); +} + void registerAllAccounts() { diff --git a/src/dring/configurationmanager_interface.h b/src/dring/configurationmanager_interface.h index 1a2000b9ef231ac4ab08130199380058817a720a..77410560246a12a022e45a9ebcff756df0ac16b0 100644 --- a/src/dring/configurationmanager_interface.h +++ b/src/dring/configurationmanager_interface.h @@ -65,6 +65,7 @@ DRING_PUBLIC bool exportToFile(const std::string& accountID, const std::string& DRING_PUBLIC bool revokeDevice(const std::string& accountID, const std::string& password, const std::string& deviceID); DRING_PUBLIC std::map<std::string, std::string> getKnownRingDevices(const std::string& accountID); DRING_PUBLIC bool changeAccountPassword(const std::string& accountID, const std::string& password_old, const std::string& password_new); +DRING_PUBLIC bool isPasswordValid(const std::string& accountID, const std::string& password); DRING_PUBLIC bool lookupName(const std::string& account, const std::string& nameserver, const std::string& name); DRING_PUBLIC bool lookupAddress(const std::string& account, const std::string& nameserver, const std::string& address); diff --git a/src/jamidht/account_manager.h b/src/jamidht/account_manager.h index 0e7baa8260be8b38d7c6f96ad7818939cfce4640..bc30f8b05afe25a7ef4275b531411d572d549952 100644 --- a/src/jamidht/account_manager.h +++ b/src/jamidht/account_manager.h @@ -121,6 +121,8 @@ public: virtual void syncDevices() = 0; + virtual bool isPasswordValid(const std::string& password) {}; + dht::crypto::Identity loadIdentity(const std::string& crt_path, const std::string& key_path, const std::string& key_pwd) const; const AccountInfo* useIdentity( diff --git a/src/jamidht/archive_account_manager.cpp b/src/jamidht/archive_account_manager.cpp index 5e4b0b914443ae91febc725f085fa9acb1d6bed7..c5f1202773e70920b156fadaf6132656e3c2cc17 100644 --- a/src/jamidht/archive_account_manager.cpp +++ b/src/jamidht/archive_account_manager.cpp @@ -673,6 +673,17 @@ ArchiveAccountManager::exportArchive(const std::string& destinationPath, const s } } +bool +ArchiveAccountManager::isPasswordValid(const std::string& password) +{ + try { + readArchive(password); + return true; + } catch (...) { + return false; + } +} + #if HAVE_RINGNS void diff --git a/src/jamidht/archive_account_manager.h b/src/jamidht/archive_account_manager.h index 8c87db387923b1d94053d1ed47c7c47f72374fec..ef7778aa1c41621774f663843de8c49fa7b011bc 100644 --- a/src/jamidht/archive_account_manager.h +++ b/src/jamidht/archive_account_manager.h @@ -60,6 +60,7 @@ public: void addDevice(const std::string& password, AddDeviceCallback) override; bool revokeDevice(const std::string& password, const std::string& device, RevokeDeviceCallback) override; bool exportArchive(const std::string& destinationPath, const std::string& password); + bool isPasswordValid(const std::string& password) override; #if HAVE_RINGNS /*void lookupName(const std::string& name, LookupCallback cb) override; @@ -97,4 +98,4 @@ private: std::string archivePath_; }; -} \ No newline at end of file +} diff --git a/src/jamidht/jamiaccount.cpp b/src/jamidht/jamiaccount.cpp index c11c3c2dfaf1a67c2a06282e102baf972553f7ad..a2425203d59b9200bc791dda280b9a4b54b0f966 100644 --- a/src/jamidht/jamiaccount.cpp +++ b/src/jamidht/jamiaccount.cpp @@ -971,6 +971,12 @@ JamiAccount::changeArchivePassword(const std::string& password_old, const std::s return true; } +bool +JamiAccount::isPasswordValid(const std::string& password) +{ + return accountManager_->isPasswordValid(password); +} + void JamiAccount::addDevice(const std::string& password) { diff --git a/src/jamidht/jamiaccount.h b/src/jamidht/jamiaccount.h index 3d7a47d952f480b626510f2a8cc55ba630b52d22..5c28f0fb1945342fb6c0419cd753992016cf1712 100644 --- a/src/jamidht/jamiaccount.h +++ b/src/jamidht/jamiaccount.h @@ -331,6 +331,8 @@ public: bool revokeDevice(const std::string& password, const std::string& device); std::map<std::string, std::string> getKnownDevices() const; + bool isPasswordValid(const std::string& password); + bool changeArchivePassword(const std::string& password_old, const std::string& password_new); void connectivityChanged() override; diff --git a/src/manager.cpp b/src/manager.cpp index 89cea7d97ead7cab566fcb23239d1b4c87f066dc..015ff69cf41ba970a9f7170cca5d33f37969b4d2 100644 --- a/src/manager.cpp +++ b/src/manager.cpp @@ -2933,6 +2933,15 @@ Manager::sendRegister(const std::string& accountID, bool enable) acc->doUnregister(); } +bool +Manager::isPasswordValid(const std::string& accountID, const std::string& password) +{ + const auto acc = getAccount<JamiAccount>(accountID); + if (!acc) + return false; + return acc->isPasswordValid(password); +} + uint64_t Manager::sendTextMessage(const std::string& accountID, const std::string& to, const std::map<std::string, std::string>& payloads) diff --git a/src/manager.h b/src/manager.h index dd972dfae5ea3aef082c77ad2fd3806078e42085..c50b7015937a811f1663dce8af6bb3a3b4a718c0 100644 --- a/src/manager.h +++ b/src/manager.h @@ -388,6 +388,8 @@ class DRING_TESTABLE Manager { */ void sendRegister(const std::string& accountId, bool enable); + bool isPasswordValid(const std::string& accountID, const std::string& password); + uint64_t sendTextMessage(const std::string& accountID, const std::string& to, const std::map<std::string, std::string>& payloads);