From d28f48a793aef1e1c07a28758c97f399f8c0a93b Mon Sep 17 00:00:00 2001 From: Jan Mulder Date: Tue, 16 Jan 2018 13:30:02 +0100 Subject: Fix preferences handling with invalid passwords This fixes 2 problems related to entering passwords with illegal characters in it: 1) Do not save an invalid password in the preferences, but keep the old one. 2) On password change, check both old and new password for format validity instead of pushing an invalid password to the server that has to ignore it. Fixes: #1048 Signed-off-by: Jan Mulder --- desktop-widgets/preferences/preferences_network.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'desktop-widgets/preferences') diff --git a/desktop-widgets/preferences/preferences_network.cpp b/desktop-widgets/preferences/preferences_network.cpp index a8cbbd70b..252694037 100644 --- a/desktop-widgets/preferences/preferences_network.cpp +++ b/desktop-widgets/preferences/preferences_network.cpp @@ -69,7 +69,12 @@ void PreferencesNetwork::syncSettings() // connect to backend server to check / create credentials QRegularExpression reg("^[a-zA-Z0-9@.+_-]+$"); if (!reg.match(email).hasMatch() || (!password.isEmpty() && !reg.match(password).hasMatch())) { - report_error(qPrintable(tr("Cloud storage email and password can only consist of letters, numbers, and '.', '-', '_', and '+'."))); + report_error(qPrintable(tr("Change ignored. Cloud storage email and password can only consist of letters, numbers, and '.', '-', '_', and '+'."))); + return; + } else if (!reg.match(email).hasMatch() || (!newpassword.isEmpty() && !reg.match(newpassword).hasMatch())) { + report_error(qPrintable(tr("Change ignored. Cloud storage email and new password can only consist of letters, numbers, and '.', '-', '_', and '+'."))); + ui->cloud_storage_new_passwd->setText(""); + return; } else { CloudStorageAuthenticate *cloudAuth = new CloudStorageAuthenticate(this); connect(cloudAuth, &CloudStorageAuthenticate::finishedAuthenticate, this, &PreferencesNetwork::updateCloudAuthenticationState); @@ -85,12 +90,15 @@ void PreferencesNetwork::syncSettings() password != prefs.cloud_storage_password) { // different credentials - reset verification status + int oldVerificationStatus = cloud->verificationStatus(); cloud->setVerificationStatus(CS_UNKNOWN); if (!email.isEmpty() && !password.isEmpty()) { // connect to backend server to check / create credentials QRegularExpression reg("^[a-zA-Z0-9@.+_-]+$"); if (!reg.match(email).hasMatch() || (!password.isEmpty() && !reg.match(password).hasMatch())) { report_error(qPrintable(tr("Cloud storage email and password can only consist of letters, numbers, and '.', '-', '_', and '+'."))); + cloud->setVerificationStatus(oldVerificationStatus); + return; } else { CloudStorageAuthenticate *cloudAuth = new CloudStorageAuthenticate(this); connect(cloudAuth, &CloudStorageAuthenticate::finishedAuthenticate, this, &PreferencesNetwork::updateCloudAuthenticationState); @@ -104,6 +112,7 @@ void PreferencesNetwork::syncSettings() QRegularExpression reg("^[a-zA-Z0-9@.+_-]+$"); if (!reg.match(email).hasMatch() || !reg.match(password).hasMatch()) { report_error(qPrintable(tr("Cloud storage email and password can only consist of letters, numbers, and '.', '-', '_', and '+'."))); + return; } CloudStorageAuthenticate *cloudAuth = new CloudStorageAuthenticate(this); connect(cloudAuth, SIGNAL(finishedAuthenticate()), this, SLOT(updateCloudAuthenticationState())); -- cgit v1.2.3-70-g09d2