diff --git a/src/cpp/model/Session.cpp b/src/cpp/model/Session.cpp index 13b359640..5b70ee1bb 100644 --- a/src/cpp/model/Session.cpp +++ b/src/cpp/model/Session.cpp @@ -415,7 +415,6 @@ bool Session::ifUserExist(const std::string& email) int Session::updateEmailVerification(Poco::UInt64 emailVerificationCode) { const static char* funcName = "Session::updateEmailVerification"; - Poco::ScopedLock _lock(mWorkMutex); // new mutex, will replace the Poco Mutex complete in the future std::unique_lock _lock_shared(mSharedMutex); @@ -796,10 +795,12 @@ UserStates Session::loadUser(const std::string& email, const std::string& passwo } } // can be removed if session user isn't used any more - if (mNewUser->getModel()->getPasswordHashed() && !mSessionUser->validatePwd(password, this)) { + // don't calculate password two times anymore + mSessionUser->login(mNewUser); + /*if (mNewUser->getModel()->getPasswordHashed() && !mSessionUser->validatePwd(password, this)) { unlock(); return USER_PASSWORD_INCORRECT; - } + }*/ } else { User::fakeCreateCryptoKey(); diff --git a/src/cpp/model/User.cpp b/src/cpp/model/User.cpp index fdba4b0b3..e36874e71 100644 --- a/src/cpp/model/User.cpp +++ b/src/cpp/model/User.cpp @@ -773,6 +773,25 @@ bool User::validatePwd(const std::string& pwd, ErrorList* validationErrorsToPrin return false; } +void User::login(Poco::AutoPtr newUser) +{ + assert(!newUser.isNull()); + assert(newUser->getModel()); + + lock("User::validatePwd"); + mPasswordHashed = newUser->getModel()->getPasswordHashed(); + auto mm = MemoryManager::getInstance(); + if (mCryptoKey) { + mm->releaseMemory(mCryptoKey); + mCryptoKey = nullptr; + } + auto keyPair = newUser->getGradidoKeyPair(); + if (keyPair) { + mCryptoKey = keyPair->getCryptedPrivKey(newUser->getPassword()); + } + unlock(); +} + bool User::validateIdentHash(HASH hash) { lock("User::validateIdentHash"); diff --git a/src/cpp/model/User.h b/src/cpp/model/User.h index 698abd44c..94bbe0678 100644 --- a/src/cpp/model/User.h +++ b/src/cpp/model/User.h @@ -77,6 +77,8 @@ public: ~User(); + void login(Poco::AutoPtr newUser); + static std::string generateNewPassphrase(Mnemonic* word_source); static bool validatePassphrase(const std::string& passphrase, Mnemonic** wordSource = nullptr); static const char* userStateToString(UserStates state);