From d20cc5d3f5417905e8e14495c5eb0f4edad2b3af Mon Sep 17 00:00:00 2001 From: Luca Beltrame Date: Sun, 8 Feb 2015 23:51:15 +0100 Subject: [PATCH] Fix connect widget Don't use winId as it breaks QQuickWidget (see Qt docs) Add an isAnonymous() function to check whether the login is there or will not be used Properly set passwords in the wallet Do the hashing properly --- src/danbooruconnectwidget.cpp | 50 +++++++++++++++++++++++------------ src/danbooruconnectwidget.h | 2 ++ 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/src/danbooruconnectwidget.cpp b/src/danbooruconnectwidget.cpp index 4232f43..7b6839d 100644 --- a/src/danbooruconnectwidget.cpp +++ b/src/danbooruconnectwidget.cpp @@ -24,6 +24,7 @@ #include "libdanbooru/danbooruservice.h" #include +#include #include @@ -64,21 +65,20 @@ DanbooruConnectWidget::DanbooruConnectWidget(QVector< QUrl > urlList, closeButton->setToolTip(i18n("Close dialog and discard changes")); userLineEdit->setClearButtonEnabled(true); passwdLineEdit->setClearButtonEnabled(true); + passwdLineEdit->setEchoMode(QLineEdit::Password); if (anonCheckBox->isChecked()) { userLineEdit->setEnabled(false); passwdLineEdit->setEnabled(false); } - WId winid = this->parentWidget()->winId(); - danbooruUrlComboBox->clear(); for (auto item : urlList) { danbooruUrlComboBox->insertUrl(urlList.indexOf(item), item); } - m_wallet = Wallet::openWallet(Wallet::NetworkWallet(), winid, + m_wallet = Wallet::openWallet(Wallet::NetworkWallet(), 0, Wallet::Asynchronous ); @@ -127,7 +127,18 @@ void DanbooruConnectWidget::getWalletData() } m_username = valueMap[QLatin1String("username")]; - m_password = valueMap[QLatin1String("password")]; + + QString hashedPassword; + + hashedPassword = boardSalts.value(m_boardUrl); + + hashedPassword = hashedPassword.arg(hashedPassword ,valueMap[QLatin1String("password")]); + hashedPassword = QCryptographicHash::hash(hashedPassword.toUtf8(), + QCryptographicHash::Sha1).toHex(); + + m_password = hashedPassword; + userLineEdit->setText(m_username); + passwdLineEdit->setText(valueMap[QLatin1String("password")]); } } @@ -165,32 +176,37 @@ QString DanbooruConnectWidget::password() const void DanbooruConnectWidget::accept() { - if (m_boardUrl.isEmpty()) { - return; - } QString hashedPassword; - if (!m_username.isEmpty() && !m_password.isEmpty()) { + if (!userLineEdit->text().isEmpty() && !passwdLineEdit->text().isEmpty()) { if (m_wallet && !m_wallet->hasEntry(m_boardUrl.url())) { QMap dataMap; dataMap.insert(QLatin1String("username"), m_username); - dataMap.insert(QLatin1String("password"), m_password); + dataMap.insert(QLatin1String("password"), passwdLineEdit->text()); m_wallet->writeMap(m_boardUrl.url(), dataMap); } - hashedPassword = boardSalts.value(m_boardUrl).arg(m_password); - hashedPassword = QCryptographicHash::hash(hashedPassword.toUtf8(), - QCryptographicHash::Sha1 - ).toHex(); + // Only calculate if we haven't set a password from the wallet already + if (m_password.isEmpty()) { + + hashedPassword = boardSalts.value(m_boardUrl); + hashedPassword = hashedPassword.arg(hashedPassword, passwdLineEdit->text()); + hashedPassword = QCryptographicHash::hash(hashedPassword.toUtf8(), + QCryptographicHash::Sha1).toHex(); + m_password = hashedPassword; + } } - DanbooruService *service = new DanbooruService(m_boardUrl, m_username, - hashedPassword); - Q_EMIT(connectionEstablished(service)); + m_boardUrl = QUrl::fromUserInput(danbooruUrlComboBox->currentText()); + Q_EMIT(accepted()); +} + +bool DanbooruConnectWidget::isAnonymous() const { + + return anonCheckBox->isChecked(); - hide(); } }; // namespace Danbooru diff --git a/src/danbooruconnectwidget.h b/src/danbooruconnectwidget.h index 4af7d55..81eb401 100644 --- a/src/danbooruconnectwidget.h +++ b/src/danbooruconnectwidget.h @@ -52,6 +52,7 @@ public: QString username() const; QString password() const; QUrl boardUrl() const; + bool isAnonymous() const; private: QUrl m_boardUrl; @@ -62,6 +63,7 @@ private: Q_SIGNALS: void connectionEstablished(DanbooruService *service); + void accepted(); void rejected(); private Q_SLOTS: