Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(chore): Fixed the problem where Regex would not accept - and . symbols #4

Closed
wants to merge 3 commits into from

Conversation

kilianbalaguer
Copy link
Member

@kilianbalaguer kilianbalaguer commented Dec 1, 2024

In the pull-request i fixed the problem of the password field telling Password must be at least 8 characters, include an uppercase letter, a number, and a special character. when using a - or a . in the password like for example tEsT-Sc1bBl!e$ab

Summary by CodeRabbit

  • New Features

    • Updated password validation to allow additional special characters (hyphens, underscores, and periods) for enhanced user flexibility during authentication and registration.
  • Bug Fixes

    • Minor formatting adjustment in the password validation function for improved code clarity.

In the pull-request i fixed the problem of the password field telling Password must be at least 8 characters, include an uppercase letter, a number, and a special character. when using a - or a . in the password like for example tEsT-Sc1bBl!e$ab
In the pull-request i fixed the problem of the password field telling Password must be at least 8 characters, include an uppercase letter, a number, and a special character. when using a - or a . in the password like for example tEsT-Sc1bBl!e$ab
Copy link

coderabbitai bot commented Dec 1, 2024

Walkthrough

The changes involve an update to the password validation logic in the AuthContent component of the src/app/auth/page.tsx file. The regular expression for password validation has been modified to allow a broader range of special characters, including hyphens, underscores, and periods. This adjustment changes the criteria for valid passwords, which may impact user authentication and registration. Additionally, a minor formatting change was made by removing an extra line break in the validatePassword function.

Changes

File Path Change Summary
src/app/auth/page.tsx Updated password validation regex to include hyphens, underscores, and periods; removed extra line break in validatePassword.

Poem

In the land of code where rabbits play,
A password's strength has found its way.
With special characters now in tow,
Hyphens and dots can join the show!
Hopping through logic, we cheer with glee,
For safer passwords, oh what a spree! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@N3v1 N3v1 self-requested a review December 1, 2024 18:20
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
src/app/auth/page.tsx (1)

73-73: LGTM! Consider improving regex readability

The updated regex correctly allows "-", "_", and "." symbols while maintaining strong password requirements.

Consider these improvements:

  1. Extract the regex to a named constant for better maintainability
  2. Add a comment explaining the pattern components
+ // Regex components:
+ // (?=.*[A-Z]) - at least one uppercase letter
+ // (?=.*\d) - at least one digit
+ // (?=.*[@$!%*?&\-_\.]) - at least one special character
+ // [A-Za-z\d@$!%*?&\-_\.]{8,} - allowed characters with minimum length of 8
+ const PASSWORD_VALIDATION_REGEX = /^(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&\-_.])[A-Za-z\d@$!%*?&\-_\.]{8,}$/;

  const validatePassword = (value: string) => {
-   const passwordRegex = /^(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&\-_.])[A-Za-z\d@$!%*?&\-_\.]{8,}$/;
+   const passwordRegex = PASSWORD_VALIDATION_REGEX;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 4967e5d and 691c056.

📒 Files selected for processing (1)
  • src/app/auth/page.tsx (1 hunks)
🔇 Additional comments (2)
src/app/auth/page.tsx (2)

79-79: Formatting change looks good


73-79: Verify consistent password validation across the codebase

Let's ensure this password validation pattern is consistently applied across all authentication-related code.

✅ Verification successful

Let me try a different approach to search for password validation patterns and authentication-related files.


Let me try one more search with a simpler pattern to find password validation logic.


Password validation is correctly implemented in a single location

The password validation is centralized in the auth page component and is consistently used for both initial validation and re-validation. The regex pattern enforces strong password requirements, and there are no conflicting implementations across the codebase. The validation is properly scoped to the authentication flow.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other password validation patterns that might need updating
rg -l 'password.*regex|regex.*password' --type ts --type tsx

# Look for other authentication-related files that might need review
fd -e ts -e tsx -E "*.test.*" -E "*.spec.*" | rg -l "auth|login|signup|register"

Length of output: 181


Script:

#!/bin/bash
# Search for password validation patterns using ripgrep
rg "(?=.*[A-Z]).*(?=.*\d).*(?=.*[@$!%*?&])" --type-add 'tsx:*.tsx' --type-add 'ts:*.ts'

# Find authentication-related files
find . -type f \( -name "*.ts" -o -name "*.tsx" \) -not -name "*.test.*" -not -name "*.spec.*" | xargs rg -l "auth|login|signup|register"

Length of output: 794


Script:

#!/bin/bash
# Check content of auth-related files for password validation
rg -A 5 "password.*=" ./src/lib/models/auth.ts ./src/app/auth/page.tsx

# Look for any password-related validation or regex patterns
rg "password.*test|validatePassword" ./src/lib/models/auth.ts ./src/app/auth/page.tsx

Length of output: 1738

@@ -70,13 +70,13 @@ function AuthContent({ router }: AuthContentProps) {

const validatePassword = (value: string) => {
const passwordRegex =
/^(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/;
/^(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&\-_.])[A-Za-z\d@$!%*?&\-_\.]{8,}$/;
setPasswordError(
passwordRegex.test(value)
Copy link
Member

Choose a reason for hiding this comment

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

@kilianbalaguer Maybe a new error message informing about invalid chars would be nice

Copy link
Member Author

Choose a reason for hiding this comment

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

YES I WILL MY KING @N3v1

Copy link

cloudflare-workers-and-pages bot commented Dec 1, 2024

Deploying scribblelabapp with  Cloudflare Pages  Cloudflare Pages

Latest commit: 691c056
Status: ✅  Deploy successful!
Preview URL: https://2ec327c3.scribblelabapp.pages.dev
Branch Preview URL: https://fix-auth-regex.scribblelabapp.pages.dev

View logs

@N3v1
Copy link
Member

N3v1 commented Dec 2, 2024

@kilianbalaguer Will you be able to complete this task within this week?

@kilianbalaguer
Copy link
Member Author

@kilianbalaguer Will you be able to complete this task within this week?

Nevio do you mean the message for unsupported character and update the other message to show the supported ones?
also does the fix of mine work now for the password?

@N3v1
Copy link
Member

N3v1 commented Dec 2, 2024

@kilianbalaguer Will you be able to complete this task within this week?

Nevio do you mean the message for unsupported character and update the other message to show the supported ones? also does the fix of mine work now for the password?

See Discord 🙂

@N3v1
Copy link
Member

N3v1 commented Jan 14, 2025

@kilianbalaguer Any plan on resolving the issues? 🙂
If you have any questions feel free to reach out to me on Discord

@N3v1 N3v1 closed this Jan 22, 2025
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.

2 participants