Skip to content
This repository was archived by the owner on Feb 5, 2026. It is now read-only.

Fix username case sensitivity and implement email login support#26

Closed
Copilot wants to merge 1 commit intomainfrom
copilot/fix-18
Closed

Fix username case sensitivity and implement email login support#26
Copilot wants to merge 1 commit intomainfrom
copilot/fix-18

Conversation

Copy link

Copilot AI commented Aug 13, 2025

This PR addresses the authentication flow issues by implementing case-insensitive username login and adding support for email-based authentication, while maintaining full backward compatibility.

Problem

The original authentication system had several limitations:

  • Username login was case-sensitive, causing failed logins due to typing mistakes
  • Users could only log in with usernames, not email addresses
  • The username field's relevance was unclear in the user interface

Solution

Implemented a comprehensive authentication improvement with minimal code changes:

Backend Changes

  • New Custom JWT Serializer (api/serializers/auth.py): Created CustomTokenObtainPairSerializer that extends SimpleJWT's functionality to support both username and email login with case-insensitive matching
  • Enhanced Authentication Logic: Uses Django's __iexact lookup for case-insensitive matching on both username and email fields
  • Automatic Input Detection: Determines whether input is an email (contains '@') or username automatically
  • Security Preservation: Maintains all existing security features including login attempt tracking, account lockout, and IP logging

Frontend Changes

  • Updated Login Form: Changed the input label from "Username" to "Username or Email" and updated the placeholder text accordingly

Technical Implementation

The solution uses Django's built-in case-insensitive lookup methods:

# Email lookup (case-insensitive)
user_obj = User.objects.get(email__iexact=username_or_email)

# Username lookup (case-insensitive) 
user_obj = User.objects.get(username__iexact=username_or_email)

Authentication Examples

All of these login methods now work seamlessly:

{"username": "johndoe", "password": "password123"}           // Traditional username
{"username": "JOHNDOE", "password": "password123"}           // Case-insensitive username
{"username": "john@example.com", "password": "password123"}  // Email login
{"username": "JOHN@EXAMPLE.COM", "password": "password123"}  // Case-insensitive email

Key Benefits

  • Enhanced User Experience: Users can login with either username or email
  • Case-Insensitive: No more failed logins due to caps lock or typing variations
  • Backward Compatible: All existing usernames continue to work exactly as before
  • Security Maintained: Preserves login attempt tracking, account lockout, and all security features
  • Minimal Changes: Surgical modifications with no breaking changes

Screenshot

The login form now clearly indicates that both username and email are accepted:

Updated Login Form

The highlighted field shows the updated label "Username or Email" with the corresponding placeholder text.

Testing

Comprehensive testing confirms:

  • Case-insensitive username matching works correctly
  • Email-based authentication functions properly
  • All existing security features remain intact
  • Backward compatibility is preserved for all existing users

This implementation addresses the core authentication issues while keeping the username field relevant and maintaining the existing user experience.

Fixes #18.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copy link
Author

Copilot AI commented Aug 13, 2025

@Jordonh18 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs.

I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review.

@Jordonh18 Jordonh18 closed this Aug 13, 2025
Copilot AI changed the title [WIP] Fix username case sensitivity and improve login/auth flow relevance Fix username case sensitivity and implement email login support Aug 13, 2025
Copilot AI requested a review from Jordonh18 August 13, 2025 14:15
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix username case sensitivity and improve login/auth flow relevance

2 participants