MCPcopy Create free account
hub / github.com/KangLin/RabbitRemoteControl / getCredentials

Method getCredentials

Plugins/WebBrowser/PasswordStore.cpp:40–78  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

38
39#if HAVE_QTKEYCHAIN
40QVariantMap CPasswordStore::getCredentials(const QString &host)
41{
42 QVariantMap result;
43 if (host.isEmpty()) return result;
44
45 const QString key = ServiceName() + QStringLiteral("autofill/%1").arg(host);
46 auto pJob = new QKeychain::ReadPasswordJob(ServiceName());
47 bool check = connect(pJob, &QKeychain::ReadPasswordJob::finished,
48 this, [this, pJob, host]() {
49 if (pJob->error() != QKeychain::NoError) {
50 qDebug(log) << "ReadPasswordJob error for" << host << ":"
51 << pJob->errorString();
52 return;
53 }
54 QString text = pJob->textData();
55 if (!text.isEmpty()) {
56 QVariantMap result;
57 // Expect JSON { "username": "...", "password": "..." }
58 QJsonDocument doc = QJsonDocument::fromJson(text.toUtf8());
59 if (doc.isObject()) {
60 QJsonObject obj = doc.object();
61 if (obj.contains(QStringLiteral("username")))
62 result["username"] = obj.value(QStringLiteral("username")).toString();
63 if (obj.contains(QStringLiteral("password")))
64 result["password"] = obj.value(QStringLiteral("password")).toString();
65 } else {
66 // Fallback: treat stored text as password only
67 result["password"] = text;
68 }
69 qDebug(log) << "Get credentials for" << host;
70 emit this->sigCredentialsReady(host, result);
71 }
72 });
73 Q_ASSERT(check);
74 pJob->setKey(key);
75 pJob->start();
76
77 return result;
78}
79
80void CPasswordStore::saveCredentials(
81 const QString &host, const QString &username, const QString &password)

Callers 1

fillFunction · 0.80

Calls 6

errorStringMethod · 0.80
startMethod · 0.80
LoadPasswordMethod · 0.80
ServiceNameFunction · 0.70
isEmptyMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected