Reduce sensitive data instances

There is no reason for `WebUI` class to retain this information.

PR #21373.
This commit is contained in:
Chocobo1 2024-09-30 17:45:28 +08:00 committed by GitHub
parent 50acb670b0
commit fd311fd5ff
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 6 deletions

View File

@ -42,7 +42,7 @@
WebUI::WebUI(IApplication *app, const QByteArray &tempPasswordHash)
: ApplicationComponent(app)
, m_passwordHash {tempPasswordHash}
, m_tempPasswordHash {tempPasswordHash}
{
configure();
connect(Preferences::instance(), &Preferences::changed, this, &WebUI::configure);
@ -54,12 +54,17 @@ void WebUI::configure()
m_errorMsg.clear();
const Preferences *pref = Preferences::instance();
m_isEnabled = pref->isWebUIEnabled();
const QString username = pref->getWebUIUsername();
if (const QByteArray passwordHash = pref->getWebUIPassword(); !passwordHash.isEmpty())
m_passwordHash = passwordHash;
QByteArray passwordHash = m_tempPasswordHash;
if (const QByteArray prefPasswordHash = pref->getWebUIPassword(); !prefPasswordHash.isEmpty())
{
passwordHash = prefPasswordHash;
m_tempPasswordHash.clear();
}
if (m_isEnabled && (username.isEmpty() || m_passwordHash.isEmpty()))
if (m_isEnabled && (username.isEmpty() || passwordHash.isEmpty()))
{
setError(tr("Credentials are not set"));
}
@ -98,7 +103,7 @@ void WebUI::configure()
}
m_webapp->setUsername(username);
m_webapp->setPasswordHash(m_passwordHash);
m_webapp->setPasswordHash(passwordHash);
if (pref->isWebUIHttpsEnabled())
{

View File

@ -77,5 +77,5 @@ private:
QPointer<Net::DNSUpdater> m_dnsUpdater;
QPointer<WebApplication> m_webapp;
QByteArray m_passwordHash;
QByteArray m_tempPasswordHash;
};