Skip to content

fix: Verification code is not case sensitive #3121

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

Merged
merged 1 commit into from
May 21, 2025
Merged

Conversation

shaohuzhang1
Copy link
Contributor

fix: Verification code is not case sensitive

@shaohuzhang1 shaohuzhang1 merged commit 289ebf4 into main May 21, 2025
4 checks passed
@shaohuzhang1 shaohuzhang1 deleted the pr@main@fix_captcha branch May 21, 2025 03:57
@@ -105,7 +105,7 @@ def is_valid(self, *, raise_exception=False):
"""
super().is_valid(raise_exception=True)
captcha = self.data.get('captcha')
captcha_value = captcha_cache.get(f"LOGIN:{captcha}")
captcha_value = captcha_cache.get(f"LOGIN:{captcha.lower()}")
if captcha_value is None:
raise AppApiException(1005, _("Captcha code error or expiration"))
username = self.data.get("username")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The provided code snippet has a few improvements and clarifications that can be made:

  1. Case Insensitivity Fix: The captcha_cache keys should be consistent to avoid errors related to case sensitivity. Change both instances where keys are formed from chars (line 63) and captcha_value (line 108). Use lowercase for uniformity, as shown:

    captcha_cache.set(f"LOGIN:{captcha.lower()}", chars, timeout=5 * 60)
  2. Code Readability: Consider adding comments at the beginning of your functions to explain what they do briefly, especially if they are large.

  3. Error Handling: Ensure you handle exceptions correctly within the is_valid method to provide meaningful feedback to the user when the captcha code is invalid or expires.

  4. Security Advice: Although not directly relevant to the code itself, it's worth considering that using passwords or captchas in plain text storage could expose sensitive information. In practice, use environment variables or secure vaults to store such credentials rather than hardcoding them in your application.

With these changes, the code will behave more robustly and securely while maintaining its functionality.

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.

1 participant