I am encountering an issue while implementing a password reset feature in my ASP.NET Core MVC application. After sending the reset token to the user's email and clicking the link to set a new password, I find that the line
var user = await _userManager.FindByEmailAsync(Input.Email);
in my ResetPassword class always returns null, even though I have confirmed that a user with the same email exists. I have verified that there is indeed a user with the specified email address by first retrieving all the users and then using a lambda expression to check the collection:
var allUsers = _userManager.Users.ToListAsync();
var user = allUsers.FirstOrDefault(x => x.Email == Input.Email);
but this also returns null for user. The next thing I tried doing is using a foreach loop to iterate through the list of users to manually verify if it's a problem with different datatypes. And I found that the string.Compare() or string1 == string2 expression always returned false when I compared both emails. Even when both were identical in case, or even if I normalized the input email beforehand.
foreach (var us1 in allUsers)
{
if (us1.Email.ToLower() == Input.Email.ToLower())
{
// Breakpoint ... Found ... I never get to this breakpoint
}
}
Strangely, I use _userManager in the Register class, and _userManager.FindByEmailAsync(Input.Email) returns the expected user.
I have checked that the email address is valid and exist in the database
I'm using ASP.NET Core MVC with Identity.
Other operations with
_userManager.FindByEmailseem to be working correctly in different parts of the application. I used in inRegister.csto implement validation that prevents two userNames from being registered with same email address.I have also verified that
UserManageris being injected into the constructor of myResetPasswordclass. I have seen other similar answers here but the suggestions didn't help.(Edit), If I use the username on userManager like so
var user = await _userManager.FindByNameAsync("username");
The above will return the correct user provided the username exist. But this is not ideal because I can't get the userName when resetting password.
Any insights or suggestions on what might be causing this issue would be greatly appreciated. Thank you!

Thanks to your suggestion @Luke Woodward. Indeed there was an extra unicode in the email address I was trying to compare. Hence why I couldn't get desired result. I didn't want to go the route of deleting all the users (to avoid data loss) so had to manually edit each email.
Works fine now.