Lot of password related changes all over the place.
Password is no longer saved with the connection list. Password is not entered along with other connection credentials. Password is now asked for when required. Still working on saving the password and auto retrieving it from the password manager.
This commit is contained in:
parent
6b9b602c64
commit
2230a4bd61
21 changed files with 508 additions and 195 deletions
|
|
@ -1,6 +1,7 @@
|
|||
#include "ConnectionList.h"
|
||||
#include "ScopeGuard.h"
|
||||
#include "util.h"
|
||||
#include "PasswordManager.h"
|
||||
#include <QDir>
|
||||
#include <QStandardPaths>
|
||||
#include <QSettings>
|
||||
|
|
@ -19,31 +20,38 @@ namespace {
|
|||
settings.setValue("hostaddr", stdStrToQ(cc.hostAddr()));
|
||||
settings.setValue("port", cc.port());
|
||||
settings.setValue("user", stdStrToQ(cc.user()));
|
||||
settings.setValue("password", stdStrToQ(cc.password()));
|
||||
//settings.setValue("password", stdStrToQ(cc.password()));
|
||||
settings.setValue("dbname", stdStrToQ(cc.dbname()));
|
||||
settings.setValue("sslmode", (int)cc.sslMode());
|
||||
settings.setValue("sslmode", static_cast<int>(cc.sslMode()));
|
||||
settings.setValue("sslcert", stdStrToQ(cc.sslCert()));
|
||||
settings.setValue("sslkey", stdStrToQ(cc.sslKey()));
|
||||
settings.setValue("sslrootcert", stdStrToQ(cc.sslRootCert()));
|
||||
settings.setValue("sslcrl", stdStrToQ(cc.sslCrl()));
|
||||
}
|
||||
|
||||
template <typename S, typename T>
|
||||
bool in_range(T value)
|
||||
{
|
||||
return value >= std::numeric_limits<S>::min() && value <= std::numeric_limits<S>::max();
|
||||
}
|
||||
|
||||
void LoadConnectionConfig(QSettings &settings, ConnectionConfig &cc)
|
||||
{
|
||||
cc.setName(qvarToStdStr(settings.value("name")));
|
||||
cc.setHost(qvarToStdStr(settings.value("host")));
|
||||
cc.setHostAddr(qvarToStdStr(settings.value("hostaddr")));
|
||||
cc.setPort(settings.value("port", 5432).toInt());
|
||||
int p = settings.value("port", 5432).toInt();
|
||||
if (!in_range<uint16_t>(p)) {
|
||||
p = 0; // let the user re-enter a valid value
|
||||
}
|
||||
|
||||
cc.setPort(static_cast<uint16_t>(p));
|
||||
cc.setUser(qvarToStdStr(settings.value("user")));
|
||||
// std::string encpw = qvarToStdStr(settings.value("encryptedpw"));
|
||||
// if (encpw.empty()) {
|
||||
cc.setPassword(qvarToStdStr(settings.value("password")));
|
||||
// }
|
||||
// else {
|
||||
// cc.setEncryptedPassword(encpw);
|
||||
// }
|
||||
|
||||
//cc.setPassword(qvarToStdStr(settings.value("password")));
|
||||
|
||||
cc.setDbname(qvarToStdStr(settings.value("dbname")));
|
||||
cc.setSslMode((SslMode)settings.value("sslmode").toInt());
|
||||
cc.setSslMode(static_cast<SslMode>(settings.value("sslmode").toInt()));
|
||||
cc.setSslCert(qvarToStdStr(settings.value("sslcert")));
|
||||
cc.setSslKey(qvarToStdStr(settings.value("sslkey")));
|
||||
cc.setSslRootCert(qvarToStdStr(settings.value("sslrootcert")));
|
||||
|
|
@ -69,19 +77,20 @@ QString ConnectionList::iniFileName()
|
|||
|
||||
ConnectionList::ConnectionList()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int ConnectionList::createNew()
|
||||
size_t ConnectionList::createNew()
|
||||
{
|
||||
m_connections.emplace_back(QUuid::createUuid(), ConnectionConfig());
|
||||
ConnectionConfig cc;
|
||||
cc.setUuid(QUuid::createUuid());
|
||||
m_connections.push_back(cc);
|
||||
return m_connections.size()-1;
|
||||
}
|
||||
|
||||
void ConnectionList::remove(int idx, int count)
|
||||
void ConnectionList::remove(size_t idx, size_t count)
|
||||
{
|
||||
auto f = m_connections.begin() + idx;
|
||||
auto l = f + count;
|
||||
auto f = m_connections.begin() + static_cast<int>(idx);
|
||||
auto l = f + static_cast<int>(count);
|
||||
deleteFromIni(f, l);
|
||||
m_connections.erase(f, l);
|
||||
}
|
||||
|
|
@ -91,7 +100,7 @@ void ConnectionList::deleteFromIni(t_Connections::iterator begin, t_Connections:
|
|||
QString file_name = iniFileName();
|
||||
QSettings settings(file_name, QSettings::IniFormat);
|
||||
for (auto i = begin; i != end; ++i) {
|
||||
settings.remove(i->m_uuid.toString());
|
||||
settings.remove(i->uuid().toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -111,8 +120,9 @@ void ConnectionList::load()
|
|||
SCOPE_EXIT { settings.endGroup(); };
|
||||
|
||||
ConnectionConfig cc;
|
||||
cc.setUuid(uuid);
|
||||
LoadConnectionConfig(settings, cc);
|
||||
m_connections.emplace_back(uuid, cc);
|
||||
m_connections.push_back(cc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -123,26 +133,24 @@ void ConnectionList::save()
|
|||
QString file_name = iniFileName();
|
||||
QSettings settings(file_name, QSettings::IniFormat);
|
||||
for (auto& e : m_connections) {
|
||||
settings.beginGroup(e.m_uuid.toString());
|
||||
settings.beginGroup(e.uuid().toString());
|
||||
SCOPE_EXIT { settings.endGroup(); };
|
||||
|
||||
SaveConnectionConfig(settings, e.m_config);
|
||||
e.m_config.clean();
|
||||
SaveConnectionConfig(settings, e);
|
||||
e.clean();
|
||||
}
|
||||
settings.sync();
|
||||
}
|
||||
|
||||
void ConnectionList::save(int index)
|
||||
void ConnectionList::save(size_t index)
|
||||
{
|
||||
if (index >= 0 && index < (int)m_connections.size()) {
|
||||
auto& e = m_connections[index];
|
||||
if (e.m_config.dirty()) {
|
||||
QString file_name = iniFileName();
|
||||
QSettings settings(file_name, QSettings::IniFormat);
|
||||
settings.beginGroup(e.m_uuid.toString());
|
||||
SaveConnectionConfig(settings, e.m_config);
|
||||
e.m_config.clean();
|
||||
settings.sync();
|
||||
}
|
||||
auto& e = m_connections.at(index);
|
||||
if (e.dirty()) {
|
||||
QString file_name = iniFileName();
|
||||
QSettings settings(file_name, QSettings::IniFormat);
|
||||
settings.beginGroup(e.uuid().toString());
|
||||
SaveConnectionConfig(settings, e);
|
||||
e.clean();
|
||||
settings.sync();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue