diff --git a/src/libsync/account.cpp b/src/libsync/account.cpp index 75b722962..076fb196d 100644 --- a/src/libsync/account.cpp +++ b/src/libsync/account.cpp @@ -517,6 +517,14 @@ void Account::writeAppPasswordOnce(QString appPassword){ if(_wroteAppPassword) return; + // Fix: Password got written from Account Wizard, before finish. + // Only write the app password for a connected account, else + // there'll be a zombie keychain slot forever, never used again ;p + // + // Also don't write empty passwords (Log out -> Relaunch) + if(id().isEmpty() || appPassword.isEmpty()) + return; + const QString kck = AbstractCredentials::keychainKey( url().toString(), davUser() + app_password, @@ -527,9 +535,14 @@ void Account::writeAppPasswordOnce(QString appPassword){ job->setInsecureFallback(false); job->setKey(kck); job->setBinaryData(appPassword.toLatin1()); - connect(job, &WritePasswordJob::finished, [this](Job *) { - qCInfo(lcAccount) << "appPassword stored in keychain"; + connect(job, &WritePasswordJob::finished, [this](Job *incoming) { + WritePasswordJob *writeJob = static_cast(incoming); + if (writeJob->error() == NoError) + qCInfo(lcAccount) << "appPassword stored in keychain"; + else + qCWarning(lcAccount) << "Unable to store appPassword in keychain" << writeJob->errorString(); + // We don't try this again on error, to not raise CPU consumption _wroteAppPassword = true; }); job->start(); @@ -574,6 +587,16 @@ void Account::deleteAppPassword(){ DeletePasswordJob *job = new DeletePasswordJob(Theme::instance()->appName()); job->setInsecureFallback(false); job->setKey(kck); + connect(job, &DeletePasswordJob::finished, [this](Job *incoming) { + DeletePasswordJob *deleteJob = static_cast(incoming); + if (deleteJob->error() == NoError) + qCInfo(lcAccount) << "appPassword deleted from keychain"; + else + qCWarning(lcAccount) << "Unable to delete appPassword from keychain" << deleteJob->errorString(); + + // Allow storing a new app password on re-login + _wroteAppPassword = false; + }); job->start(); }