1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-24 04:36:34 +01:00

[PasswordManager] Added DatabaseEncryptedPasswordBackend.

-It uses AesInterface for all encryption/decryption (AES 256 CBC)
This commit is contained in:
S. Razi Alavizadeh 2013-06-08 17:41:38 +04:30
parent 102d90b77b
commit 05755158f9
7 changed files with 921 additions and 11 deletions

View File

@ -0,0 +1,642 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2013 S. Razi Alavizadeh <s.r.alavizadeh@gmail.com>
* Copyright (C) 2013 David Rosca <nowrep@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
#include "databaseencryptedpasswordbackend.h"
#include "mainapplication.h"
#include "autofill.h"
#include "aesinterface.h"
#include "qupzilla.h"
#include "ui_masterpassworddialog.h"
#include <QVector>
#include <QSqlQuery>
#include <QInputDialog>
#include <QMessageBox>
#include <QDebug>
#define INTERNAL_SERVER_ID QLatin1String("qupzilla.internal")
DatabaseEncryptedPasswordBackend::DatabaseEncryptedPasswordBackend()
: PasswordBackend()
, m_stateOfMasterPassword(UnKnownState)
{
QSqlDatabase db = QSqlDatabase::database();
if (!db.tables().contains(QLatin1String("autofill_encrypted"))) {
db.exec("CREATE TABLE autofill_encrypted (data_encrypted TEXT, id INTEGER PRIMARY KEY,"
"password_encrypted TEXT, server TEXT, username_encrypted TEXT, last_used NUMERIC)");
db.exec("CREATE INDEX autofillEncryptedServer ON autofill_encrypted(server ASC)");
}
}
DatabaseEncryptedPasswordBackend::~DatabaseEncryptedPasswordBackend()
{
}
QVector<PasswordEntry> DatabaseEncryptedPasswordBackend::getEntries(const QUrl &url)
{
QVector<PasswordEntry> list;
AesInterface aesDecryptor;
const QString &host = PasswordManager::createHost(url);
QSqlQuery query;
query.prepare("SELECT id, username_encrypted, password_encrypted, data_encrypted FROM autofill_encrypted "
"WHERE server=? ORDER BY last_used DESC");
query.addBindValue(host);
query.exec();
while (query.next()) {
PasswordEntry data;
data.id = query.value(0);
data.host = host;
data.username = query.value(1).toString();
data.password = query.value(2).toString();
data.data = query.value(3).toByteArray();
if (decryptPasswordEntry(&data, &aesDecryptor)) {
list.append(data);
}
}
return list;
}
QVector<PasswordEntry> DatabaseEncryptedPasswordBackend::getAllEntries()
{
QVector<PasswordEntry> list;
AesInterface aesDecryptor;
QSqlQuery query;
query.exec("SELECT id, server, username_encrypted, password_encrypted, data_encrypted FROM autofill_encrypted");
while (query.next()) {
PasswordEntry data;
data.id = query.value(0);
data.host = query.value(1).toString();
if (data.host == INTERNAL_SERVER_ID) {
continue;
}
data.username = query.value(2).toString();
data.password = query.value(3).toString();
data.data = query.value(4).toByteArray();
if (decryptPasswordEntry(&data, &aesDecryptor)) {
list.append(data);
}
}
return list;
}
void DatabaseEncryptedPasswordBackend::setActive(bool active)
{
if (active == isActive()) {
return;
}
PasswordBackend::setActive(active);
if (active) {
setAskMasterPasswordState(isMasterPasswordSetted());
if (!isMasterPasswordSetted()) {
// master-password is not setted this backend needs master-password
showMasterPasswordDialog();
}
}
else {
// maybe ask from user for decrypting data
// remove password from memory
m_masterPassword.clear();
setAskMasterPasswordState(isMasterPasswordSetted());
}
}
void DatabaseEncryptedPasswordBackend::addEntry(const PasswordEntry &entry)
{
// Data is empty only for HTTP/FTP authorization
if (entry.data.isEmpty()) {
// Multiple-usernames for HTTP/FTP authorization not supported
QSqlQuery query;
query.prepare("SELECT username_encrypted FROM autofill_encrypted WHERE server=?");
query.addBindValue(entry.host);
query.exec();
if (query.next()) {
return;
}
}
PasswordEntry encryptedEntry = entry;
AesInterface aesEncryptor;
if (encryptPasswordEntry(&encryptedEntry, &aesEncryptor)) {
QSqlQuery query;
query.prepare("INSERT INTO autofill_encrypted (server, data_encrypted, username_encrypted, password_encrypted, last_used) "
"VALUES (?,?,?,?,strftime('%s', 'now'))");
query.bindValue(0, encryptedEntry.host);
query.bindValue(1, encryptedEntry.data);
query.bindValue(2, encryptedEntry.username);
query.bindValue(3, encryptedEntry.password);
query.exec();
}
}
bool DatabaseEncryptedPasswordBackend::updateEntry(const PasswordEntry &entry)
{
AesInterface aesEncryptor;
PasswordEntry encryptedEntry = entry;
if (encryptPasswordEntry(&encryptedEntry, &aesEncryptor)) {
QSqlQuery query;
// Data is empty only for HTTP/FTP authorization
if (entry.data.isEmpty()) {
query.prepare("UPDATE autofill_encrypted SET username_encrypted=?, password_encrypted=? WHERE server=?");
query.bindValue(0, encryptedEntry.username);
query.bindValue(1, encryptedEntry.password);
query.bindValue(2, encryptedEntry.host);
}
else {
query.prepare("UPDATE autofill_encrypted SET data_encrypted=?, username_encrypted=?, password_encrypted=? WHERE id=?");
query.addBindValue(encryptedEntry.data);
query.addBindValue(encryptedEntry.username);
query.addBindValue(encryptedEntry.password);
query.addBindValue(encryptedEntry.id);
}
return query.exec();
}
return false;
}
void DatabaseEncryptedPasswordBackend::updateLastUsed(PasswordEntry &entry)
{
QSqlQuery query;
query.prepare("UPDATE autofill_encrypted SET last_used=strftime('%s', 'now') WHERE id=?");
query.addBindValue(entry.id);
query.exec();
}
void DatabaseEncryptedPasswordBackend::removeEntry(const PasswordEntry &entry)
{
if (!hasPermission()) {
return;
}
QSqlQuery query;
query.prepare("DELETE FROM autofill_encrypted WHERE id=?");
query.addBindValue(entry.id);
query.exec();
m_stateOfMasterPassword = UnKnownState;
if (someDataFromDatabase().isEmpty()) {
updateSampleData(m_masterPassword);
}
}
void DatabaseEncryptedPasswordBackend::removeAll()
{
if (!hasPermission()) {
return;
}
QSqlQuery query;
query.prepare("DELETE FROM autofill_encrypted");
query.exec();
m_stateOfMasterPassword = PasswordIsSetted;
updateSampleData(m_masterPassword);
}
QString DatabaseEncryptedPasswordBackend::name() const
{
return AutoFill::tr("Database (encrypted)");
}
void DatabaseEncryptedPasswordBackend::showSettings(QWidget* parent)
{
MasterPasswordDialog* masterPasswordDialog = new MasterPasswordDialog(this, parent);
masterPasswordDialog->showSettingPage();
}
bool DatabaseEncryptedPasswordBackend::isMasterPasswordSetted()
{
if (m_stateOfMasterPassword == UnKnownState) {
m_stateOfMasterPassword = someDataFromDatabase().isEmpty() ? PasswordIsNotSetted : PasswordIsSetted;
}
return m_stateOfMasterPassword == PasswordIsSetted;
}
QByteArray DatabaseEncryptedPasswordBackend::masterPassword() const
{
return m_masterPassword;
}
bool DatabaseEncryptedPasswordBackend::hasPermission()
{
if (!m_askMasterPassword) {
return true;
}
bool ok;
QString text = QInputDialog::getText(mApp->getWindow(), AutoFill::tr("Enter Master Password"),
AutoFill::tr("Permission is required, please enter Master Password:"),
QLineEdit::Password, QString(), &ok);
if (ok && !text.isEmpty()) {
QByteArray enteredPassword = AesInterface::passwordToHash(text);
if (!isPasswordVerified(enteredPassword)) {
QMessageBox::information(mApp->getWindow(), AutoFill::tr("Warning!"), AutoFill::tr("Entered password is wrong!"));
setAskMasterPasswordState(true);
return false;
}
else {
setAskMasterPasswordState(false);
//TODO: start timer for reset ask state to true
return true;
}
}
return false;
}
bool DatabaseEncryptedPasswordBackend::isPasswordVerified(const QByteArray &password)
{
if (password.isEmpty()) {
return false;
}
if (m_masterPassword == password) {
return true;
}
else if (!m_masterPassword.isEmpty()) {
return false;
}
else {
// m_masterPassword is empty we need to check entered password with
// decoding some data by it and then save it to m_masterPassword
AesInterface aes;
aes.decrypt(someDataFromDatabase(), password);
if (aes.isOk()) {
m_masterPassword = password;
return true;
}
}
return false;
}
bool DatabaseEncryptedPasswordBackend::decryptPasswordEntry(PasswordEntry* entry, AesInterface* aesInterface)
{
if (!hasPermission() || !entry) {
return false;
}
entry->username = QString::fromUtf8(aesInterface->decrypt(entry->username.toUtf8(), m_masterPassword));
entry->password = QString::fromUtf8(aesInterface->decrypt(entry->password.toUtf8(), m_masterPassword));
entry->data = aesInterface->decrypt(entry->data, m_masterPassword);
return aesInterface->isOk();
}
bool DatabaseEncryptedPasswordBackend::encryptPasswordEntry(PasswordEntry* entry, AesInterface* aesInterface)
{
if (!hasPermission() || !entry) {
return false;
}
entry->username = QString::fromUtf8(aesInterface->encrypt(entry->username.toUtf8(), m_masterPassword));
entry->password = QString::fromUtf8(aesInterface->encrypt(entry->password.toUtf8(), m_masterPassword));
entry->data = aesInterface->encrypt(entry->data, m_masterPassword);
return aesInterface->isOk();
}
void DatabaseEncryptedPasswordBackend::showMasterPasswordDialog()
{
MasterPasswordDialog* masterPasswordDialog = new MasterPasswordDialog(this, mApp->getWindow());
masterPasswordDialog->showSetMasterPasswordPage();
}
void DatabaseEncryptedPasswordBackend::tryToChangeMasterPassword(const QByteArray &newPassword)
{
if (m_masterPassword == newPassword) {
return;
}
if (newPassword.isEmpty()) {
removeMasterPassword();
return;
}
encryptDataBaseTableOnFly(m_masterPassword, newPassword);
m_masterPassword = newPassword;
updateSampleData(m_masterPassword);
}
void DatabaseEncryptedPasswordBackend::removeMasterPassword()
{
if (!m_masterPassword.isEmpty()) {
encryptDataBaseTableOnFly(m_masterPassword, QByteArray());
m_masterPassword.clear();
updateSampleData(QByteArray());
}
}
void DatabaseEncryptedPasswordBackend::encryptDataBaseTableOnFly(const QByteArray &decryptorPassword, const QByteArray &encryptorPassword)
{
if (encryptorPassword == decryptorPassword) {
return;
}
QSqlQuery query;
query.prepare("SELECT id, data_encrypted, password_encrypted, username_encrypted, server FROM autofill_encrypted");
query.exec();
AesInterface encryptor;
AesInterface decryptor;
while (query.next()) {
QString server = query.value(4).toString();
if (server == INTERNAL_SERVER_ID) {
continue;
}
int id = query.value(0).toInt();
QByteArray data = query.value(1).toString().toUtf8();
QByteArray password = query.value(2).toString().toUtf8();
QByteArray username = query.value(3).toString().toUtf8();
if (!decryptorPassword.isEmpty()) {
data = decryptor.decrypt(data, decryptorPassword);
password = decryptor.decrypt(password, decryptorPassword);
username = decryptor.decrypt(username, decryptorPassword);
}
if (!encryptorPassword.isEmpty()) {
data = encryptor.encrypt(data, encryptorPassword);
password = encryptor.encrypt(password, encryptorPassword);
username = encryptor.encrypt(username, encryptorPassword);
}
QSqlQuery updateQuery;
updateQuery.prepare("UPDATE autofill_encrypted SET data_encrypted = ?, password_encrypted = ?, username_encrypted = ? WHERE id = ?");
updateQuery.addBindValue(data);
updateQuery.addBindValue(password);
updateQuery.addBindValue(username);
updateQuery.addBindValue(id);
updateQuery.exec();
}
}
QByteArray DatabaseEncryptedPasswordBackend::someDataFromDatabase()
{
if (m_stateOfMasterPassword != UnKnownState && !m_someDataStoredOnDataBase.isEmpty()) {
return m_someDataStoredOnDataBase;
}
QSqlQuery query;
query.prepare("SELECT password_encrypted, data_encrypted, username_encrypted FROM autofill_encrypted");
query.exec();
QByteArray someData;
if (query.next()) {
int i = 0;
while (someData.isEmpty()) {
if (i > 2) {
if (query.next()) {
i = 0;
continue;
}
else {
break;
}
}
someData = query.value(i).toByteArray();
++i;
}
}
m_someDataStoredOnDataBase = someData;
return m_someDataStoredOnDataBase;
}
void DatabaseEncryptedPasswordBackend::updateSampleData(const QByteArray &password)
{
QSqlQuery query;
query.prepare("SELECT id FROM autofill_encrypted WHERE server = ?");
query.addBindValue(INTERNAL_SERVER_ID);
query.exec();
if (!password.isEmpty()) {
AesInterface aes;
m_someDataStoredOnDataBase = aes.encrypt(AesInterface::createRandomData(16), password);
if (query.next()) {
query.prepare("UPDATE autofill_encrypted SET password_encrypted = ? WHERE server=?");
}
else {
query.prepare("INSERT INTO autofill_encrypted (password_encrypted, server) VALUES (?,?)");
}
query.addBindValue(QString::fromUtf8(m_someDataStoredOnDataBase));
query.addBindValue(INTERNAL_SERVER_ID);
query.exec();
m_stateOfMasterPassword = PasswordIsSetted;
}
else if (query.next()) {
query.prepare("DELETE FROM autofill_encrypted WHERE server = ?");
query.addBindValue(INTERNAL_SERVER_ID);
query.exec();
m_stateOfMasterPassword = PasswordIsNotSetted;
m_someDataStoredOnDataBase.clear();
return;
}
}
/******************************
* MasterPasswordDialog class *
******************************/
#include <QTimer>
MasterPasswordDialog::MasterPasswordDialog(DatabaseEncryptedPasswordBackend* backend, QWidget* parent)
: QDialog(parent, Qt::MSWindowsFixedSizeDialogHint)
, ui(new Ui::MasterPasswordDialog)
, m_backend(backend)
{
setAttribute(Qt::WA_DeleteOnClose, true);
ui->setupUi(this);
ui->currentPassword->setVisible(m_backend->isMasterPasswordSetted());
ui->labelCurrentPassword->setVisible(m_backend->isMasterPasswordSetted());
connect(ui->setMasterPassword, SIGNAL(clicked()), this, SLOT(showSetMasterPasswordPage()));
connect(ui->clearMasterPassword, SIGNAL(clicked()), this, SLOT(clearMasterPasswordAndConvert()));
connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
connect(ui->buttonBoxMasterPassword, SIGNAL(rejected()), this, SLOT(reject()));
connect(ui->buttonBoxMasterPassword, SIGNAL(accepted()), this, SLOT(accept()));
}
MasterPasswordDialog::~MasterPasswordDialog()
{
delete ui;
}
void MasterPasswordDialog::delayedExec()
{
QTimer::singleShot(0, this, SLOT(exec()));
}
void MasterPasswordDialog::accept()
{
if (ui->stackedWidget->currentIndex() != 1) {
QDialog::accept();
return;
}
QByteArray currentPassField = AesInterface::passwordToHash(ui->currentPassword->text());
if (m_backend->isMasterPasswordSetted() && !m_backend->isPasswordVerified(currentPassField)) {
QMessageBox::information(this, tr("Warning!"), tr("You entred wrong password!"));
return;
}
if (ui->newPassword->text() != ui->confirmPassword->text()) {
QMessageBox::information(this, tr("Warning!"), tr("New/Confirm password fields don't match!"));
return;
}
if (ui->newPassword->text().isEmpty()) {
if (!m_backend->isMasterPasswordSetted()) {
return;
}
clearMasterPasswordAndConvert(false);
}
else {
// for security reason we don't save master-password as plain in memory
QByteArray newPassField = AesInterface::passwordToHash(ui->newPassword->text());
if (m_backend->masterPassword() != newPassField) {
m_backend->tryToChangeMasterPassword(newPassField);
}
}
QDialog::accept();
}
void MasterPasswordDialog::reject()
{
QDialog::reject();
if (m_backend->isActive() && !m_backend->isMasterPasswordSetted()) {
// master password not setted
QMessageBox::information(this, AutoFill::tr("Warning!"),
AutoFill::tr("This backend needs a master password setted! "
"QupZilla just switch to its default backend"));
// active default backend
mApp->autoFill()->passwordManager()->switchBackend("database");
return;
}
}
void MasterPasswordDialog::showSettingPage()
{
ui->stackedWidget->setCurrentIndex(0);
delayedExec();
}
void MasterPasswordDialog::showSetMasterPasswordPage()
{
disconnect(ui->setMasterPassword, SIGNAL(clicked()), this, SLOT(showSetMasterPasswordPage()));
ui->stackedWidget->setCurrentIndex(1);
delayedExec();
connect(ui->setMasterPassword, SIGNAL(clicked()), this, SLOT(showSetMasterPasswordPage()));
}
void MasterPasswordDialog::clearMasterPasswordAndConvert(bool forcedAskPass)
{
if (QMessageBox::information(this, tr("Warning!"), tr("Are you sure to clear master password and decrypt data?"), QMessageBox::Yes | QMessageBox::No)
== QMessageBox::No) {
reject();
return;
}
if (forcedAskPass) {
m_backend->setAskMasterPasswordState(true);
}
if (m_backend->hasPermission()) {
QVector<PasswordEntry> list = m_backend->getAllEntries();
PasswordBackend* databaseBackend = mApp->autoFill()->passwordManager()->availableBackends().value("database");
if (!databaseBackend) {
return;
}
QVector<PasswordEntry> databaseList = databaseBackend->getAllEntries();
bool allDataMoved = true;
foreach (const PasswordEntry &entry, list) {
foreach (const PasswordEntry &dbEntry, databaseList) {
if (!samePasswordEntry(dbEntry, entry)) {
databaseBackend->addEntry(entry);
m_backend->removeEntry(entry);
}
else {
allDataMoved = false;
}
}
}
if (allDataMoved) {
m_backend->removeAll();
m_backend->removeMasterPassword();
m_backend->setAskMasterPasswordState(false);
mApp->autoFill()->passwordManager()->switchBackend("database");
}
else {
QMessageBox::information(this, tr("Warning!"), tr("There are some data that were not decrypted. The master password was not cleared!"));
}
}
reject();
}
bool MasterPasswordDialog::samePasswordEntry(const PasswordEntry &entry1, const PasswordEntry &entry2)
{
if (entry1.host != entry2.host || entry1.username != entry2.username) {
return false;
}
return true;
}

View File

@ -0,0 +1,122 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2013 S. Razi Alavizadeh <s.r.alavizadeh@gmail.com>
* Copyright (C) 2013 David Rosca <nowrep@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
#ifndef DATABASEENCRYPTEDPASSWORDBACKEND_H
#define DATABASEENCRYPTEDPASSWORDBACKEND_H
#include "passwordbackend.h"
#include "qz_namespace.h"
#include <QDialog>
class AesInterface;
class MasterPasswordDialog;
class QT_QUPZILLA_EXPORT DatabaseEncryptedPasswordBackend : public PasswordBackend
{
public:
enum MasterPasswordState {
PasswordIsSetted,
PasswordIsNotSetted,
UnKnownState = -1
};
explicit DatabaseEncryptedPasswordBackend();
~DatabaseEncryptedPasswordBackend();
QVector<PasswordEntry> getEntries(const QUrl &url);
QVector<PasswordEntry> getAllEntries();
void setActive(bool active);
void addEntry(const PasswordEntry &entry);
bool updateEntry(const PasswordEntry &entry);
void updateLastUsed(PasswordEntry &entry);
void removeEntry(const PasswordEntry &entry);
void removeAll();
QString name() const;
inline bool hasSettings() const { return true; }
void showSettings(QWidget* parent);
bool isMasterPasswordSetted();
QByteArray masterPassword() const;
bool hasPermission();
bool isPasswordVerified(const QByteArray &password);
bool decryptPasswordEntry(PasswordEntry* entry, AesInterface* aesInterface);
bool encryptPasswordEntry(PasswordEntry* entry, AesInterface* aesInterface);
void tryToChangeMasterPassword(const QByteArray &newPassword);
void removeMasterPassword();
inline void setAskMasterPasswordState(bool ask) { m_askMasterPassword = ask; }
void encryptDataBaseTableOnFly(const QByteArray &decryptorPassword,
const QByteArray &encryptorPassword);
void updateSampleData(const QByteArray &password);
void showMasterPasswordDialog();
private:
QByteArray someDataFromDatabase();
MasterPasswordState m_stateOfMasterPassword;
QByteArray m_someDataStoredOnDataBase;
bool m_askMasterPassword;
QByteArray m_masterPassword;
MasterPasswordDialog* m_masterPasswordDialog;
};
namespace Ui
{
class MasterPasswordDialog;
}
class MasterPasswordDialog : public QDialog
{
Q_OBJECT
public:
explicit MasterPasswordDialog(DatabaseEncryptedPasswordBackend* backend, QWidget* parent = 0);
~MasterPasswordDialog();
void delayedExec();
public slots:
void accept();
void reject();
void showSettingPage();
void showSetMasterPasswordPage();
void clearMasterPasswordAndConvert(bool forcedAskPass = true);
bool samePasswordEntry(const PasswordEntry &entry1, const PasswordEntry &entry2);
private:
Ui::MasterPasswordDialog* ui;
DatabaseEncryptedPasswordBackend* m_backend;
};
#endif // DATABASEENCRYPTEDPASSWORDBACKEND_H

View File

@ -0,0 +1,136 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MasterPasswordDialog</class>
<widget class="QDialog" name="MasterPasswordDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>343</width>
<height>231</height>
</rect>
</property>
<property name="windowTitle">
<string>Encrypted DataBase Settings</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QStackedWidget" name="stackedWidget">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="pageSettings">
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QCommandLinkButton" name="setMasterPassword">
<property name="text">
<string>Set/Change Master Password...</string>
</property>
<property name="description">
<string>This backend doesn't work without master password.</string>
</property>
</widget>
</item>
<item>
<widget class="QCommandLinkButton" name="clearMasterPassword">
<property name="text">
<string>Clear Master Password...</string>
</property>
<property name="description">
<string>This option clears master password and moves all encrypted data to &quot;DataBase (Plain Text)&quot; backend, and switch to it.</string>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Close</set>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="pageSetMasterPassword">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label_4">
<property name="text">
<string>The Master Password is used to protect site passwords and form data. If you set Master Password you will be asked to enter it once per session.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="labelCurrentPassword">
<property name="text">
<string>Current Password:</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>New Password:</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Confirm Password:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="currentPassword">
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="newPassword">
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="confirmPassword">
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>&lt;b&gt;Note:&lt;/b&gt; Master Password is not resetable. Don't forgot it, please.</string>
</property>
<property name="textFormat">
<enum>Qt::RichText</enum>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBoxMasterPassword">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -18,6 +18,7 @@
#include "passwordmanager.h"
#include "passwordbackends/passwordbackend.h"
#include "passwordbackends/databasepasswordbackend.h"
#include "passwordbackends/databaseencryptedpasswordbackend.h"
#include "settings.h"
#include <QVector>
@ -62,8 +63,10 @@ PasswordManager::PasswordManager(QObject* parent)
, m_loaded(false)
, m_backend(0)
, m_databaseBackend(new DatabasePasswordBackend)
, m_databaseEncryptedBackend(new DatabaseEncryptedPasswordBackend)
{
m_backends["database"] = m_databaseBackend;
m_backends["database-encrypted"] = m_databaseEncryptedBackend;
}
void PasswordManager::loadSettings()
@ -202,4 +205,5 @@ void PasswordManager::ensureLoaded()
PasswordManager::~PasswordManager()
{
delete m_databaseBackend;
delete m_databaseEncryptedBackend;
}

View File

@ -26,6 +26,7 @@
class PasswordBackend;
class DatabasePasswordBackend;
class DatabaseEncryptedPasswordBackend;
struct QT_QUPZILLA_EXPORT PasswordEntry {
QVariant id;
@ -89,6 +90,8 @@ private:
PasswordBackend* m_backend;
DatabasePasswordBackend* m_databaseBackend;
DatabaseEncryptedPasswordBackend* m_databaseEncryptedBackend;
QHash<QString, PasswordBackend*> m_backends;
signals:

View File

@ -244,7 +244,8 @@ SOURCES += \
autofill/passwordmanager.cpp \
autofill/passwordbackends/databasepasswordbackend.cpp \
autofill/passwordbackends/passwordbackend.cpp \
tools/aesinterface.cpp
tools/aesinterface.cpp \
autofill/passwordbackends/databaseencryptedpasswordbackend.cpp
HEADERS += \
@ -425,7 +426,8 @@ HEADERS += \
autofill/passwordmanager.h \
autofill/passwordbackends/passwordbackend.h \
autofill/passwordbackends/databasepasswordbackend.h \
tools/aesinterface.h
tools/aesinterface.h \
autofill/passwordbackends/databaseencryptedpasswordbackend.h
FORMS += \
preferences/autofillmanager.ui \
@ -474,7 +476,8 @@ FORMS += \
session/recoverywidget.ui \
tools/html5permissions/html5permissionsnotification.ui \
tools/html5permissions/html5permissionsdialog.ui \
autofill/autofillwidget.ui
autofill/autofillwidget.ui \
autofill/passwordbackends/masterpassworddialog.ui
RESOURCES += \
data/icons.qrc \

View File

@ -220,19 +220,19 @@ void AutoFillManager::editPass()
bool ok;
QString text = QInputDialog::getText(this, tr("Edit password"), tr("Change password:"), QLineEdit::Normal, entry.password, &ok);
if (ok && !text.isEmpty()) {
if (ok && !text.isEmpty() && text != entry.password) {
QByteArray oldPass = "=" + PasswordManager::urlEncodePassword(entry.password);
entry.data.replace(oldPass, "=" + PasswordManager::urlEncodePassword(text));
entry.password = text;
QVariant v;
v.setValue<PasswordEntry>(entry);
curItem->setData(0, Qt::UserRole + 10, v);
if (mApp->autoFill()->updateEntry(entry)) {
QVariant v;
v.setValue<PasswordEntry>(entry);
curItem->setData(0, Qt::UserRole + 10, v);
mApp->autoFill()->updateEntry(entry);
if (m_passwordsShown) {
curItem->setText(2, text);
if (m_passwordsShown) {
curItem->setText(2, text);
}
}
}
}