Skip to content

Fixed password strength logic with details#7

Merged
ericbsd merged 1 commit intomasterfrom
fixing-password-strengt
Dec 13, 2025
Merged

Fixed password strength logic with details#7
ericbsd merged 1 commit intomasterfrom
fixing-password-strengt

Conversation

@ericbsd
Copy link
Member

@ericbsd ericbsd commented Dec 12, 2025

Summary by Sourcery

Strengthen password validation to require specific combinations of character types for different complexity tiers.

Bug Fixes:

  • Correct password mix_character validation to ensure required combinations of lowercase/uppercase letters and digits are present.
  • Update lower_upper_number validation to require at least one lowercase, one uppercase, and one digit.
  • Tighten all_character validation to require lowercase, uppercase, digits, and special characters instead of just allowing them.

Enhancements:

  • Document the intent of password validation regex patterns with inline comments for maintainability.

@ericbsd ericbsd requested review from a team as code owners December 12, 2025 11:54
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Dec 12, 2025

Reviewer's Guide

Adjusts password validation regexes to enforce actual presence of character classes instead of just allowing them, and documents the patterns with inline comments.

Flow diagram for updated password complexity checks

flowchart TD
    A_Start[Start password validation] --> B[Input password]
    B --> C{"is_same_type(password)?"}
    C -->|Yes| C1[Password uses a single character type<br/>only_lower_or_upper_or_digits]
    C -->|No| D{"mix_character(password)?"}
    D -->|Yes| D1[Password uses exactly two classes<br/>lower+digit or upper+digit or lower+upper]
    D -->|No| E{"lower_upper_number(password)?"}
    E -->|Yes| E1[Password uses three classes<br/>lower+upper+digit]
    E -->|No| F{"all_character(password)?"}
    F -->|Yes| F1[Password uses four classes<br/>lower+upper+digit+special]
    F -->|No| G[Password fails complexity rules]
    C1 --> H_End[Return lowest complexity tier]
    D1 --> H_End
    E1 --> H_End
    F1 --> H_End
    G --> H_End
Loading

File-Level Changes

Change Details Files
Clarified and documented simple same-type password detection regex.
  • Added inline comments explaining the lowercase, uppercase, and digit-only regex patterns used for same-type detection
setup_station/common.py
Strengthened mixed-character password validation to require combinations of character classes rather than just allowing them.
  • Replaced broad class-allowing regex with lookahead-based patterns that enforce at least one lowercase+digit, uppercase+digit, or lowercase+uppercase combination
  • Reformatted the regex call over multiple lines for readability and added explanatory comments for each pattern
setup_station/common.py
Updated higher-complexity password validators to enforce presence of required character classes instead of merely restricting allowed characters.
  • Changed lower/upper/number validator to require at least one lowercase, uppercase, and digit using lookaheads, and updated docstring accordingly
  • Changed all-character validator to require at least one lowercase, uppercase, digit, and special character using lookaheads, and updated docstring accordingly
  • Added inline comments describing the intent and structure of the complexity regexes and wrapped the longer pattern in a multi-line re.match call
setup_station/common.py

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

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes - here's some feedback:

  • The new regex patterns in mix_character, lower_upper_number, and all_character are quite dense; consider extracting them into named constants or small helper functions with descriptive names to improve readability and maintainability.
  • You can simplify the patterns and make intent clearer by using re.fullmatch instead of anchoring with ^ and $, which will also remove some visual noise from the regex strings.
  • Given the repeated use of character-class checks (lowercase, uppercase, digits, specials), it may be cleaner and less error-prone to implement these using any(c.islower() for c in text)-style checks rather than complex lookahead regexes.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new regex patterns in `mix_character`, `lower_upper_number`, and `all_character` are quite dense; consider extracting them into named constants or small helper functions with descriptive names to improve readability and maintainability.
- You can simplify the patterns and make intent clearer by using `re.fullmatch` instead of anchoring with `^` and `$`, which will also remove some visual noise from the regex strings.
- Given the repeated use of character-class checks (lowercase, uppercase, digits, specials), it may be cleaner and less error-prone to implement these using `any(c.islower() for c in text)`-style checks rather than complex lookahead regexes.

## Individual Comments

### Comment 1
<location> `setup_station/common.py:58` </location>
<code_context>
-    return bool(re.match(r'^[a-zA-Z0-9]+$', text))
+    # ^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])[a-zA-Z0-9]+$ - must have lowercase AND uppercase AND digit,
+    # only letters/digits allowed
+    return bool(re.match(r'^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])[a-zA-Z0-9]+$', text))


</code_context>

<issue_to_address>
**suggestion:** Use `re.fullmatch` instead of `re.match` with explicit anchors.

Across these validators you combine `re.match` with `^...$`. Prefer `re.fullmatch`, which removes the need for anchors, clarifies that the whole string must match, and avoids future bugs if an anchor is accidentally removed, e.g. `re.fullmatch(r'(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])[a-zA-Z0-9]+', text)`.

Suggested implementation:

```python
    # ^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])[a-zA-Z0-9]+$ - must have lowercase AND uppercase AND digit,
    # only letters/digits allowed
    return bool(re.fullmatch(r'(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])[a-zA-Z0-9]+', text))

```

```python
    return bool(
        re.fullmatch(

```

There are likely other validators in `setup_station/common.py` following the same pattern (`re.match` with `^...$`). For consistency and to fully implement your review comment, you should:
1. Search for all `re.match(` usages in this file.
2. For patterns anchored with `^` and `$`, convert them to `re.fullmatch` and remove the anchors.
3. Ensure that any tests expecting partial matches are not inadvertently changed; only validators requiring full-string validation should be updated.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@ericbsd ericbsd merged commit 35d1225 into master Dec 13, 2025
2 checks passed
@ericbsd ericbsd deleted the fixing-password-strengt branch December 13, 2025 18:24
@ericbsd ericbsd moved this from In Review to Done in Development Tracker Jan 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant