From 05837114c7a8d5ed8b4e4c762f2ef7e8a324630d Mon Sep 17 00:00:00 2001 From: liujiangtao Date: Thu, 12 Nov 2026 16:01:43 +0800 Subject: [PATCH] fix: login fails after retrying with the correct password MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. Serialize DDM requests and disable the password field and login buttons while authentication is pending. 2. Track the submitted user and clear pending state on matching activation, authentication failure, socket error, or disconnect. 3. Skip empty password submissions for accounts that require a password. Log: Fix login failure when a correct password follows a wrong one. Influence: 1. Hold Enter or click repeatedly during unlock and verify one pending request. 2. Verify an activation for another user keeps the controls disabled. Retry with the correct password after a failed attempt. 3. Verify that empty input is ignored and passwordless login still works. fix: 输入错误密码后再输入正确密码登录失败 1. 逐次提交 DDM 认证请求,等待结果时禁用密码框和登录按钮。 2. 记录提交时的用户名,在该用户会话激活、认证失败、socket 报错或断开时结束等待。 3. 需要密码的账户在密码框为空时跳过提交。 Log: 输入错误密码后再输入正确密码登录失败 Influence: 1. 解锁时长按回车或连续点击,确认同时只有一笔请求在等待结果。 2. 等待期间收到其他用户的激活消息时确认控件仍禁用,认证失败后输入正确密码重试。 3. 确认普通密码框为空时不提交,免密账户仍可登录。 PMS: BUG-383137 --- src/greeter/greeterproxy.cpp | 29 ++++++++++++++++++++++++ src/greeter/greeterproxy.h | 23 +++++++++++++++++++ src/plugins/lockscreen/qml/UserInput.qml | 6 ++++- 3 files changed, 57 insertions(+), 1 deletion(-) diff --git a/src/greeter/greeterproxy.cpp b/src/greeter/greeterproxy.cpp index 58b2e411bb..01ccad7418 100644 --- a/src/greeter/greeterproxy.cpp +++ b/src/greeter/greeterproxy.cpp @@ -196,6 +196,21 @@ void GreeterProxy::setLock(bool isLocked) setShowShutdownView(false); } +void GreeterProxy::beginAuthentication(const QString &user) +{ + m_authenticationUser = user; + Q_EMIT authPendingChanged(); +} + +void GreeterProxy::finishAuthentication() +{ + if (!authPending()) + return; + + m_authenticationUser.clear(); + Q_EMIT authPendingChanged(); +} + /////////// // Slots // /////////// @@ -227,6 +242,9 @@ void GreeterProxy::hybridSleep() void GreeterProxy::login(const QString &user, const QString &password, const int sessionIndex) { + if (authPending()) + return; + if (!m_socket->isValid()) { qCDebug(lcTlGreeter) << "Socket is not valid. Local password check."; if (localValidation(user, password)) { @@ -243,11 +261,15 @@ void GreeterProxy::login(const QString &user, const QString &password, const int // send command to the daemon QString name = sessionModel()->data(index, SessionModel::FileRole).toString(); qCInfo(lcTlGreeter) << "Logging user" << user << "in with session" << name; + beginAuthentication(user); SocketWriter(m_socket) << quint32(GreeterMessages::Login) << user << password << name; } void GreeterProxy::unlock(const QString &user, const QString &password) { + if (authPending()) + return; + if (!m_socket->isValid()) { qCDebug(lcTlGreeter) << "Socket is not valid. Local password check."; if (localValidation(user, password)) { @@ -261,6 +283,7 @@ void GreeterProxy::unlock(const QString &user, const QString &password) auto userInfo = userModel()->get(user); if (userInfo.isValid()) { qCInfo(lcTlGreeter) << "Unlocking user" << user; + beginAuthentication(user); SocketWriter(m_socket) << quint32(GreeterMessages::Unlock) << user << password; } } @@ -469,12 +492,14 @@ void GreeterProxy::disconnected() { qCWarning(lcTlGreeter) << "Disconnected from the ddm"; + finishAuthentication(); Q_EMIT socketDisconnected(); } void GreeterProxy::error() { qCCritical(lcTlGreeter) << "Socket error: " << m_socket->errorString(); + finishAuthentication(); } void GreeterProxy::readyRead() @@ -556,6 +581,7 @@ void GreeterProxy::readyRead() qCDebug(lcTlGreeter) << "Message received from daemon: LoginFailed" << user; + finishAuthentication(); Q_EMIT failedAttemptsChanged(++m_failedAttempts); } break; case DaemonMessages::InformationMessage: { @@ -592,6 +618,9 @@ void GreeterProxy::readyRead() if (!input.commitTransaction()) return; + if (user == m_authenticationUser) + finishAuthentication(); + // NOTE: maybe DDM will active dde user. if (!userModel()->getUser(user)) { qCInfo(lcTlGreeter) << "activate user, but switch to greeter"; diff --git a/src/greeter/greeterproxy.h b/src/greeter/greeterproxy.h index 06fced041c..efe2573ca3 100644 --- a/src/greeter/greeterproxy.h +++ b/src/greeter/greeterproxy.h @@ -37,6 +37,7 @@ class GreeterProxy Q_PROPERTY(bool isLocked READ isLocked NOTIFY lockChanged) Q_PROPERTY(bool undecided READ undecided NOTIFY undecidedChanged) Q_PROPERTY(int failedAttempts READ failedAttempts NOTIFY failedAttemptsChanged) + Q_PROPERTY(bool authPending READ authPending NOTIFY authPendingChanged) Q_PROPERTY(bool showShutdownView READ showShutdownView WRITE setShowShutdownView NOTIFY showShutdownViewChanged) Q_PROPERTY(bool showAnimation READ showAnimation NOTIFY showAnimationChanged) Q_PROPERTY(bool hasActiveSession READ hasActiveSession NOTIFY hasActiveSessionChanged) @@ -114,6 +115,14 @@ class GreeterProxy */ inline int failedAttempts() const { return m_failedAttempts; }; + /** + * @brief Get whether DDM authentication is pending + * QML uses this property to disable the password field and login buttons. + * + * @return true if a login or unlock request is awaiting a result + */ + inline bool authPending() const { return !m_authenticationUser.isEmpty(); }; + /** * @brief Get whether the shutdown view is shown * QML elements should listen to this property to show/hide the shutdown view @@ -296,6 +305,9 @@ private Q_SLOTS: /** @brief Emitted when failed attempts changes. See failedAttempts() */ void failedAttemptsChanged (int failedAttempts); + /** @brief Emitted when the authentication pending state changes. See authPending() */ + void authPendingChanged(); + /** @brief Emitted when showShutdownView changes. See showShutdownView() */ void showShutdownViewChanged (bool showShutdownView); @@ -321,6 +333,16 @@ private Q_SLOTS: */ void setLock(bool isLocked); + /** + * @brief Start waiting for the given user's authentication result. + * + * @param user Username submitted in the login or unlock request + */ + void beginAuthentication(const QString &user); + + /** @brief Clear the pending authentication request, if any. */ + void finishAuthentication(); + /** * @brief Update the DDM communication socket */ @@ -346,6 +368,7 @@ private Q_SLOTS: bool m_undecided { true }; QTimer *m_undecidedTimer{ nullptr }; int m_failedAttempts { 0 }; + QString m_authenticationUser; bool m_showShutdownView { false }; bool m_showAnimation { true }; bool m_hasActiveSession { false }; diff --git a/src/plugins/lockscreen/qml/UserInput.qml b/src/plugins/lockscreen/qml/UserInput.qml index 9ca6c61c61..cdd26ab07c 100644 --- a/src/plugins/lockscreen/qml/UserInput.qml +++ b/src/plugins/lockscreen/qml/UserInput.qml @@ -107,6 +107,7 @@ Item { width: loginGroup.width height: 30 anchors.horizontalCenter: parent.horizontalCenter + enabled: !GreeterProxy.authPending TextField { id: passwordField @@ -271,7 +272,7 @@ Item { bottom: userCol.bottom leftMargin: 20 } - enabled: passwordField.length != 0 + enabled: passwordField.length != 0 && !GreeterProxy.authPending font: D.DTK.fontManager.t8 background: RoundBlur { anchors.fill: parent @@ -398,6 +399,9 @@ Item { } function userLogin() { + if (!loginGroup.noPasswdLogin && passwordField.length === 0) + return + let user = UserModel.get(UserModel.currentUserName) let pwd = loginGroup.noPasswdLogin ? "" : passwordField.text if (user.loggedIn)