Fixed password strength logic with details#7
Merged
Conversation
Contributor
Reviewer's GuideAdjusts 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 checksflowchart 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
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
There was a problem hiding this comment.
Hey there - I've reviewed your changes - here's some feedback:
- The new regex patterns in
mix_character,lower_upper_number, andall_characterare 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.fullmatchinstead 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>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary by Sourcery
Strengthen password validation to require specific combinations of character types for different complexity tiers.
Bug Fixes:
Enhancements: