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

Handle Login Drift #1132

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tabascq
Copy link
Contributor

@tabascq tabascq commented Jan 3, 2025

For years, we've been beset by a small number of users losing access to their accounts, needing manual reset at extremely inopportune times.

After a good deal of code review and web searching, I've finally discovered that a) this is normal and b) there is a simple bit of code that can be used for automatic and instantaneous account recovery.

I've tested this by mangling my local DB ProviderKey values, and observing that it successfully self-heals with the user being none the wiser.

Fixes #1073, though does it in a better way than expected.

For years, we've been beset by a small number of users losing access to their accounts, needing manual reset at extremely inopportune times.

After a good deal of code review and web searching, I've finally discovered that a) this is normal and b) there is a simple bit of code that can be used for automatic and instantaneous account recovery.

I've tested this by mangling my local DB ProviderKey values, and observing that it successfully self-heals with the user being none the wiser.

Fixes PuzzleServer#1073, though does it in a better way than expected.
@tabascq tabascq requested review from morganbr and asyasky January 3, 2025 07:41
// Search the codebase for "RequireUniqueEmail" for the code that requires this.
services.Configure<IdentityOptions>(options =>
{
options.User.RequireUniqueEmail = true;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note that I have not verified that emails are actually unique at present; I would not be surprised if some staffers have some duplication generated during server development, or perhaps some migrations have left stale users behind. Verification/cleanup is required before this code can be merged.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I've had to delete the existing AspNet user in order to fix this issue in the past, so I suspect there are few to no duplicates.

Copy link
Contributor

@digit01Wave digit01Wave left a comment

Choose a reason for hiding this comment

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

I am not that well versed in authentication, but the change looks fine to me

@tabascq
Copy link
Contributor Author

tabascq commented Jan 3, 2025

I'd like @asyasky or @morganbr to ring in on this as well, and also to help determine how many duplicate emails we currently have in the DB so we can decide how best to remove them before merging.

@tabascq
Copy link
Contributor Author

tabascq commented Jan 4, 2025

Actually, if you agree that the query below is the right query, we may be all set as it returns zero results:

SELECT Email, COUNT(*)
FROM [dbo].[AspNetUsers]
GROUP BY Email
HAVING COUNT(*) > 1;

@morganbr
Copy link
Contributor

Actually, if you agree that the query below is the right query, we may be all set as it returns zero results:

SELECT Email, COUNT(*)
FROM [dbo].[AspNetUsers]
GROUP BY Email
HAVING COUNT(*) > 1;

Yes, this is good

@asyasky
Copy link
Collaborator

asyasky commented Jan 10, 2025

I don't think we have any way to verify that this is what's causing our problem, but I don't see any downsides to trying it and it sets us up for the multiple logins feature, which is a nice bonus. :) This is exciting!

Copy link
Collaborator

@asyasky asyasky left a comment

Choose a reason for hiding this comment

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

This looks good to me, but I asked Morgan to check me on the duplicates sql query (I think it looks ok but my sql is pretty meh).

// Search the codebase for "RequireUniqueEmail" for the code that requires this.
services.Configure<IdentityOptions>(options =>
{
options.User.RequireUniqueEmail = true;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I've had to delete the existing AspNet user in order to fix this issue in the past, so I suspect there are few to no duplicates.

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.

Generate recovery link for mangled accounts
4 participants