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

Make Username and Email Case-Insensitive #586

Merged
merged 13 commits into from
Aug 21, 2020

Conversation

JosephGaynier
Copy link
Contributor

@JosephGaynier JosephGaynier commented Aug 12, 2020

I make username and email ToLower whenever it is sent to a controller.


This change is Reviewable

@JosephGaynier JosephGaynier linked an issue Aug 12, 2020 that may be closed by this pull request
@JosephGaynier JosephGaynier marked this pull request as draft August 12, 2020 17:34
Copy link
Contributor

@jasonleenaylor jasonleenaylor left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 2 files at r1.
Reviewable status: 1 of 2 files reviewed, all discussions resolved


Backend/Controllers/UserController.cs, line 40 at r2 (raw file):

        public async Task<IActionResult> ResetPasswordRequest([FromBody] PasswordResetData data)
        {
            var email = data.Email.ToLower();

I recommend using ToLowerInvariant()
There are some weird edge cases where the result could depend on the localization language.
We aren't localizing the backend yet, but we will need to in the future in order to get translations of the invitation e-mails.

@JosephGaynier JosephGaynier marked this pull request as ready for review August 13, 2020 21:30
@JosephGaynier
Copy link
Contributor Author


Backend/Controllers/UserController.cs, line 40 at r2 (raw file):

Previously, jasonleenaylor (Jason Naylor) wrote…

I recommend using ToLowerInvariant()
There are some weird edge cases where the result could depend on the localization language.
We aren't localizing the backend yet, but we will need to in the future in order to get translations of the invitation e-mails.

Gotcha, I've switched em.

@johnthagen
Copy link
Collaborator


Backend/Controllers/UserController.cs, line 40 at r3 (raw file):

        public async Task<IActionResult> ResetPasswordRequest([FromBody] PasswordResetData data)
        {
            var email = data.Email.ToLowerInvariant();

In the backend unit tests, Util.RandString() is used to create user names. The implementation of that only uses the characters a through z (lower case).

This means we aren't currently testing that lower casing is being applied in the UserController. Could the unit tests be updated to test that lower-casing is being applied?

@johnthagen johnthagen self-requested a review August 14, 2020 12:15
Copy link
Contributor

@jasonleenaylor jasonleenaylor left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 1 files at r3.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @johnthagen)


Backend/Controllers/UserController.cs, line 40 at r3 (raw file):

Previously, johnthagen wrote…

In the backend unit tests, Util.RandString() is used to create user names. The implementation of that only uses the characters a through z (lower case).

This means we aren't currently testing that lower casing is being applied in the UserController. Could the unit tests be updated to test that lower-casing is being applied?

We'll address this unit test in a follow up PR.

@JosephGaynier
Copy link
Contributor Author


Backend/Controllers/UserController.cs, line 40 at r3 (raw file):

Previously, jasonleenaylor (Jason Naylor) wrote…

We'll address this unit test in a follow up PR.

Currently working on tests right now

@johnthagen
Copy link
Collaborator


Backend/Controllers/UserController.cs, line 40 at r3 (raw file):

Previously, StevesBro wrote…

Currently working on tests right now

Created separate follow on ticket per Jason's comment: #628

Copy link
Collaborator

@johnthagen johnthagen left a comment

Choose a reason for hiding this comment

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

Reviewed 2 of 2 files at r4.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved

@JosephGaynier JosephGaynier merged commit 1d1c357 into master Aug 21, 2020
@JosephGaynier JosephGaynier deleted the CaseInsensitiveUserNameAndEmail branch August 21, 2020 13:55
@johnthagen
Copy link
Collaborator

johnthagen commented Aug 21, 2020

@StevesBro @jmgrady @imnasnainaec Does this PR require a DB fix up? Users with capital letters in their user name or password saved in the database before this PR wouldn't be able to log in right?

If they had a username User, now when they log in the controller will lower it and compare to user, which wouldn't match, right?


Edit: maybe not, it looks like we are lowering from the database too:

            var userList = await _userDatabase.Users.FindAsync(x =>
                x.Username.ToLowerInvariant() == username.ToLowerInvariant());

I guess the only risk might be if two users had been using similar names (User and user) and now we couldn't distinguish them?

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.

Make user IDs case-insensitive
4 participants