Skip to content

fix: login fails after retrying with the correct password - #1639

Merged
wineee merged 1 commit into
linuxdeepin:masterfrom
gugullll:fix/password_err
Nov 16, 2026
Merged

wineee merged 1 commit into
linuxdeepin:masterfrom
gugullll:fix/password_err

Conversation

@gugullll

@gugullll gugullll commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor
  1. Submit one authentication request at a time from the login screen.
  2. Allow another request after a result or a socket 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. Click repeatedly or hold Enter during unlock and verify one pending request.
  2. Retry after a failed attempt and verify that a new request is sent.
  3. Verify that empty input is ignored and passwordless login still works.

fix: 输入错误密码后再输入正确密码登录失败

  1. 登录界面同时只提交一笔认证请求。
  2. 收到结果或认证连接断开后允许再次提交。
  3. 需要密码的账户在密码框为空时跳过提交。

Log: 输入错误密码后再输入正确密码登录失败

Influence:

  1. 解锁时连续点击或长按回车,确认同时只有一笔请求在等待结果。
  2. 认证失败后重试,确认可以发送新的请求。
  3. 确认空密码输入被忽略,免密账户仍可登录。

PMS: BUG-383137

Summary by Sourcery

Ensure login and unlock accept only one authentication request at a time and reliably allow retries after the request completes.

Bug Fixes:

  • Prevent login and unlock failures caused by duplicate submissions and retries after an incorrect password.
  • Ignore empty password submissions for password-protected accounts while preserving passwordless login.

Enhancements:

  • Expose authentication request state to the greeter UI and release it after authentication results, socket errors, or disconnections.
  • Disable login controls while an authentication request is pending.

@sourcery-ai

sourcery-ai Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Data structures

Add the stored pending-user state and expose its authentication-pending property and notification for the greeter UI.

  • src/greeter/greeterproxy.h L118-125, L336-345 (+3 small edits)

Implementation

Serialize login and unlock requests, track the submitted user, and clear pending state on authentication failure, socket errors or disconnect, or activation of that user.

  • src/greeter/greeterproxy.cpp L199-213 (+8 small edits)

UI

Disable the password field and login button while authentication is pending, and ignore empty passwords for accounts that require one while retaining passwordless login.

  • src/plugins/lockscreen/qml/UserInput.qml L110, L275, L402-404

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/plugins/lockscreen/qml/UserInput.qml" line_range="408" />
<code_context>
+
         let user = UserModel.get(UserModel.currentUserName)
         let pwd = loginGroup.noPasswdLogin ? "" : passwordField.text
+        loginGroup.authenticationPending = true
         if (user.loggedIn)
             GreeterProxy.unlock(user.name, pwd)
</code_context>
<issue_to_address>
**Lock-screen retries stay blocked**

When the service stays connected without returning a result, a socket error occurs without a disconnect, or an initial login succeeds while `GreeterProxy` is not locked and the same view is reused, `authenticationPending` is cleared only by `failedAttemptsChanged` and `socketDisconnected`; in these cases it stays true, so later `userLogin()` calls are ignored and the user cannot retry or unlock.

Clear `authenticationPending` on every authentication success and failure, and provide a reset path for timeouts and socket errors that do not disconnect.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@gugullll
gugullll force-pushed the fix/password_err branch 2 times, most recently from 95deb3e to 746687d Compare November 12, 2026 09:07
Comment thread src/greeter/greeterproxy.cpp Resolved
wineee
wineee previously approved these changes Nov 12, 2026

@Groveer Groveer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

整体方向没问题(一次只挂一笔 DDM 认证请求 + 等待期间禁用输入),空密码的 guard 也有价值(空密码会让 PAM 返回失败,从而误报“密码错误”并累加 failedAttempts)。几点建议,主要是状态表达可以更准和pending 卡死的兜底:

  1. user != "dde" 换成“消息里的 user 是否就是本次请求的 user”,特例和 bool 成员一起消失。
  2. 补 pending 的兜底:ddm 有“收下请求但不回复”的路径,一旦漏回复,输入控件会永久禁用(详见行内评论)。
  3. 丢弃重复请求补一行日志;守卫挪到发包前;login()/unlock() 收敛成 beginAuthentication() / finishAuthentication()。
  4. QML 三处同款 enabled 绑定收敛为一处;header 的 doc / 对齐按文件既有风格补齐。

改完大概是这个形状(本地改过一版验证:greeterproxy.cpp.o 过 -Wall -Wextra -Werror,qmllint 无语法错误):

bool GreeterProxy::beginAuthentication(const QString &user)
{
    if (authenticationPending()) {
        qCDebug(lcTlGreeter) << "Authentication for" << m_authenticationUser
                             << "is still pending, ignore request for" << user;
        return false;
    }

    m_authenticationUser = user;
    Q_EMIT authenticationPendingChanged();
    return true;
}

void GreeterProxy::finishAuthentication()
{
    if (!authenticationPending())
        return;

    m_authenticationUser.clear();
    Q_EMIT authenticationPendingChanged();
}
// login(): 放在 socket 校验之后、发包之前
if (!beginAuthentication(user))
    return;

// unlock()
if (userInfo.isValid() && beginAuthentication(user)) {
    qCInfo(lcTlGreeter) << "Unlocking user" << user;
    SocketWriter(m_socket) << quint32(GreeterMessages::Unlock) << user << password;
}

// LoginFailed / 断连 / error:finishAuthentication();
// UserActivateMessage:if (user == m_authenticationUser) finishAuthentication();

这些都不阻塞合并,但第 2 点是会让用户彻底登不进去的回归风险,建议至少先把兜底加上。

Comment thread src/greeter/greeterproxy.cpp Resolved
Comment thread src/greeter/greeterproxy.cpp Resolved
Comment thread src/greeter/greeterproxy.cpp Resolved
Comment thread src/greeter/greeterproxy.cpp Resolved
Comment thread src/greeter/greeterproxy.h Resolved
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
Groveer
Groveer previously approved these changes Nov 12, 2026
@gugullll
gugullll marked this pull request as draft November 12, 2026 12:59
@gugullll
gugullll dismissed stale reviews from Groveer and wineee via 0583711 November 12, 2026 13:01
@gugullll
gugullll marked this pull request as ready for review November 12, 2026 13:02
@gugullll gugullll added the bug Something isn't working label Nov 13, 2026

@deepin-wm deepin-wm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

代码审查:fix: login fails after retrying with the correct password

结论:没有阻塞项,可以合并。 但我建议顺手补一处兜底,理由见第三节第 1 条——现在的写法一旦漏一条 DDM 回包,代价比原 bug 更重。

方向是对的:把「同时只挂一笔 DDM 认证请求」做成 GreeterProxy 里的显式状态,QML 只消费状态,比上一版用 bool + "dde" 特例干净得多。

审查范围:3 文件 / +57 −1,head 05837114c,base master。三个文件逐行过完,另外核对了 ddm 侧的回包契约(Display::login() / unlock()、TreelandDisplayServer::activateUser() / onLoginFailed())。

一、上一轮意见的落实情况

上轮意见 现状
user != "dde" 魔法字符串 已删,改成 user == m_authenticationUser(greeterproxy.cpp:621),语义正确:ddm 侧 Display::login() 本来就拒绝 dde 的登录请求
authenticationPending 和 user 两份状态 已合并成「m_authenticationUser 非空即 pending」(greeterproxy.h:124),finishAuthentication() 带幂等判断,不会重复发信号
守卫挪到发包前 / 补一条丢弃日志 守卫仍在 socket 校验之前,但你的反驳成立:pending 存续期间 socket 必然有效,本地 PAM 兜底这条分支本来就到不了,无实际差异;日志不加也接受
begin/finish 命名收敛 已按此实现,setAuthenticationPending(bool) 那种「随手动一下」的用法没了
QML 三处同款绑定 收敛为 passwordSlot(UserInput.qml:110)+ loginBtn(:275)两处,passwordField / noPwdLoginBtn 随父项生效
header 的 doc / 对齐 getter 的 @brief / @return、信号注释、Q_PROPERTY 对齐都补齐了,现在和邻居一致

二、改动正确性(已确认)

  1. 状态机闭合:pending 只在 4 处被清——disconnected(:495)、error(:502)、LoginFailed(:584)、匹配到本人 UserActivateMessage(:622)。这几处覆盖了 ddm 现有的全部回包出口:成功走 startUserSession() → activateSession() → activateUser() → UserActivateMessage,失败走 loginFailed() → LoginFailed 广播。
  2. 本地 PAM 兜底没被挡住:beginAuthentication() 在两处都在 m_socket->isValid() 分支之后调用,socket 无效时走 localValidation(),不会留下 pending。
  3. 空密码拦截放在 QML 是对的:noPasswdLogin 来自 AccountsService 的 noPassword(user.cpp:33 → UserModel),免密账户走 noPwdLoginBtn 分支不受影响;需要密码的账户空提交只会让 PAM 返回失败并被累加成一次「密码错误」误报,现在直接不提交,符合预期。
  4. 没有把整个锁屏一起锁死:只禁用了 passwordSlot 和 loginBtn,关机/重启视图仍然可用——这点很关键,见下一条建议。

三、建议(非阻塞)

  1. pending 缺少恢复路径,命中后比原 bug 更严重(行内评论附在 greeterproxy.cpp:202)。ddm 当前 master 仍有「收下请求但不回包」的分支,而 treeland 侧只有 socket 报错/断开才清 pending;漏一条回包就是锁屏输入永久禁用,用户只能重启或切 VT。你在 12:48 的回复里把触发条件定位到「treeland 重启 + 旧会话仍存活」,并靠 linuxdeepin/ddm#123 修掉——但那个 PR 目前仍是 open。建议加一行兜底(lock() / ShowGreeter / SwitchToGreeter 分支里 finishAuthentication()),或仿 m_undecidedTimer 加超时。
  2. 两处清理的判据不一致(行内评论附在 greeterproxy.cpp:584):LoginFailed 不比对用户就清,UserActivateMessage 比对。行为我不反对(广播语义下无条件清更安全),但建议补一行注释说明是有意为之。
  3. PR 描述里点明依赖:建议写一句「依赖 DDM 每条 Login / Unlock 必须有且只有一个回包」,并指向你提的 ddm PR。否则后人会把客户端这份状态当成可靠的,而不是 ddm 契约的镜像。

四、四维度

维度 结论
语法逻辑 ✓ 状态机闭合,清理幂等,两个入口的守卫一致;无未初始化路径
代码质量 ✓ 与文件既有风格(getter doc、命名、分区块)一致,改动面最小,没有多余的抽象
代码性能 ✓ 每笔请求一次 QString 拷贝 + 一次属性通知,可忽略
代码安全 ✓ 不新增信任边界;空密码不再触发无意义的 PAM 失败,反而少了一条误报路径

五、本地验证情况(诚实标注)

  • qmllint 过 UserInput.qml:只有本机 dtk 缺 dtk6declarative.qmltypes 的 import 告警,无语法错误。
  • 未编译 C++:本机没有 treeland 的完整依赖(waylib / wlroots / DDM Messages.h),greeterproxy.cpp 未单独编译,结论基于 diff + 周边代码静态分析。
  • 用 QtTest 实测了「父项 enabled=false 后再置 true」的焦点行为:activeFocus 会回到密码框。也就是说 onFailedAttemptsChanged 里那句 if (loginGroup.activeFocus) passwordField.forceActiveFocus() 不会因为等待期间禁用输入而失效(这条我原本怀疑是回归,已验证不是)。
  • ddm 侧结论基于 linuxdeepin/ddm 当前 master 的 src/daemon/Display.cpp:login() 的 auth->authenticated 早退分支仍在(:286),unlock() 在找不到活跃会话时回 loginFailed(:568)。

void GreeterProxy::beginAuthentication(const QString &user)
{
m_authenticationUser = user;
Q_EMIT authPendingChanged();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pending 只有 4 个出口(disconnected / error / LoginFailed / 匹配用户的 UserActivateMessage),既没有超时,也没有「greeter 重新出现」时的重置。而 ddm 侧现在仍有静默丢弃的路径,linuxdeepin/ddm master src/daemon/Display.cpp:286:

if (auth->authenticated) {
    qWarning() << "Existing authentication ongoing, aborting";
    return;   // 不给 greeter 回包
}

你在 12:48 的回复里把它的触发条件定位成「treeland 重启 + 旧会话仍存活」,并靠 linuxdeepin/ddm#123 修掉——但那个 PR 目前还是 open。在这条路径命中期间:

  • 改之前:Login 被 ddm 静默吞掉,界面只是「点了没反应」,用户再点一次即可;
  • 改之后:m_authenticationUser 永远非空 → 密码框和登录按钮永久灰掉 → 用户只能重启或切 VT。

这个不对称值得用一行兜底挡住(进入新一轮 greeter 会话时不可能有合法在途请求):

void GreeterProxy::lock()
{
    // 卡死的 pending 不能带进新一轮锁屏/登录
    finishAuthentication();
    ...
}

ShowGreeter / SwitchToGreeter 分支同理。更彻底的做法是超时(仿 m_undecidedTimer:超时后 finishAuthentication() + 一条提示),但一行重置已经能把「永久锁死」降级成「重进一次锁屏就好」。

另外 ddm 那个分支本身建议改成 Q_EMIT loginFailed(socket, user),可以并进你已有的那个 ddm PR——客户端的状态永远只是 ddm 回包契约的镜像,契约有洞时客户端只能自保。


qCDebug(lcTlGreeter) << "Message received from daemon: LoginFailed" << user;

finishAuthentication();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

两处清理的判据不一致:UserActivateMessage 会比较 user == m_authenticationUser(:621),这里不比对就直接清。

考虑到 TreelandDisplayServer::onLoginFailed() 是向所有 greeter socket 广播,而 greeter 侧一次只可能有一笔在途请求,无条件清其实是更安全的选择(反过来会导致用户名形态不一致时卡死),所以行为我不反对。建议补一行注释说明是有意为之(「任何失败回执都视为本轮结束,不比对用户名」),否则下次有人看到 :621 的比对,会以为这里漏了判断。

@wineee
wineee merged commit 1059408 into linuxdeepin:master Nov 16, 2026
5 of 7 checks passed
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: gugullll, wineee

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants