Skip to content

Fix Exercise 3.4 solution to count consecutive wrong passwords#1192

Merged
martin-henz merged 3 commits into
masterfrom
fix/ex-3-4-consecutive-1138
Jun 15, 2026
Merged

Fix Exercise 3.4 solution to count consecutive wrong passwords#1192
martin-henz merged 3 commits into
masterfrom
fix/ex-3-4-consecutive-1138

Conversation

@martin-henz

Copy link
Copy Markdown
Member

Fixes a logic error in the Exercise 3.4 solution (xml/chapter3/section1/subsection1.xml), reported by GitHub user KrNor in #1138.

Problem

Exercise 3.4 asks to call call_the_cops after seven consecutive accesses with an incorrect password. The solution counted total failed attempts and never reset, so a correct access in between still accumulated toward the limit.

Fix

Reset the counter on a correct password:

if (p === q) {
    invalid_attempts = 0; // reset after a correct password
    return ...

Checks (simulated in Node)

  • The existing hidden example (eight consecutive wrong attempts) still escalates to call_the_cops, so the snippet's <EXPECTED> value is unchanged.
  • After a correct password, six further wrong attempts no longer trigger the cops — whereas under the old total-counting logic they would have. Confirms consecutive counting now works.
  • XML well-formed.

Note: the issue also suggested adding a commented-out successful request to the example. I left the example as-is — it's a hidden test snippet with an <EXPECTED> value, so a commented line wouldn't be visible to readers and would break <EXPECTED> if uncommented. Happy to add a proper reset-demonstrating example if you'd prefer.

Closes #1138

Exercise 3.4 calls the cops after seven *consecutive* accesses with an
incorrect password, but the solution counted total failed attempts and
never reset. Reset invalid_attempts to 0 on a correct password.

The existing example (eight consecutive wrong attempts) still escalates
to call_the_cops, so the snippet's EXPECTED value is unchanged.

Reported by GitHub user KrNor in #1138.

Closes #1138

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request adds a reset for invalid_attempts to 0 upon a correct password entry in the dispatch function. However, a logic bug was identified where a user is locked out on their 8th attempt even if they enter the correct password, because the check invalid_attempts < 7 prevents the password from being verified once the limit is reached. A restructuring of the function is suggested to resolve this issue.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread xml/chapter3/section1/subsection1.xml Outdated
@martin-henz martin-henz enabled auto-merge (squash) June 15, 2026 02:00
@martin-henz martin-henz merged commit 634dbce into master Jun 15, 2026
4 checks passed
@martin-henz martin-henz deleted the fix/ex-3-4-consecutive-1138 branch June 15, 2026 02:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error in the solution to Exercise 3.4

1 participant