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

UserName and Email in Identity core #45938

Closed
codelovercc opened this issue Jan 7, 2023 · 4 comments
Closed

UserName and Email in Identity core #45938

codelovercc opened this issue Jan 7, 2023 · 4 comments
Labels
area-identity Includes: Identity and providers Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. Status: No Recent Activity

Comments

@codelovercc
Copy link

codelovercc commented Jan 7, 2023

Thanks anyone who build and support this great project!
Why does username must be an email in Identity core default UI? UserName is user's name and it doesn't matter if it's a email or not. Since I don't want use the email as the UserName, I can't not log in with default Identity core UI.

I found this source code in Microsoft.AspNetCore.Identity.SignInManager<TUser>.PasswordSignInAsync

public virtual async Task<SignInResult> PasswordSignInAsync(
      string userName,
      string password,
      bool isPersistent,
      bool lockoutOnFailure)
    {
      TUser byNameAsync = await this.UserManager.FindByNameAsync(userName);
      return (object) byNameAsync == null ? SignInResult.Failed : await this.PasswordSignInAsync(byNameAsync, password, isPersistent, lockoutOnFailure);
    }

and about this line TUser byNameAsync = await this.UserManager.FindByNameAsync(userName); , I think it should call await this.UserManager.FindByEmailAsync(userEmail) because of the UI Login form shows a Email input tag. Other ways it should take normal UserName as login model, UserName can be any thing and it can be a email too.

@codelovercc
Copy link
Author

Or it should be like this

public virtual async Task<SignInResult> PasswordSignInAsync(
      string userNameOrEmail,
      string password,
      bool isPersistent,
      bool lockoutOnFailure)
    {
      TUser byNameOrEmailAsync = IsEmail(userNameOrEmail) ? await this.UserManager.FindByEmailAsync(userNameOrEmail) : await this.UserManager.FindByNameAsync(userNameOrEmail);
      return (object) byNameOrEmail == null ? SignInResult.Failed : await this.PasswordSignInAsync(byNameOrEmail, password, isPersistent, lockoutOnFailure);
    }

Using FindByEmailAsync or FindByNameAsync to find a TUser.

@mkArtakMSFT mkArtakMSFT added the area-identity Includes: Identity and providers label Jan 8, 2023
@captainsafia
Copy link
Member

captainsafia commented Jan 12, 2023

Triage: The two are conflated for historical reasons. If you want the two to be separate, you'd have to produce a scaffold with username and email as separate fields.

I found this source code in Microsoft.AspNetCore.Identity.SignInManager.PasswordSignInAsync

To resolve this, you'd have to find the username by the email before invoking the PasswordSignInAsync. There's no API to do this currently.

Dupe of #44660

@captainsafia captainsafia added the Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. label Jan 12, 2023
@ghost
Copy link

ghost commented Jan 12, 2023

Hi @codelovercc. We have added the "Needs: Author Feedback" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@ghost
Copy link

ghost commented Jan 16, 2023

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate.

See our Issue Management Policies for more information.

@ghost ghost closed this as completed Jan 19, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Feb 19, 2023
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-identity Includes: Identity and providers Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. Status: No Recent Activity
Projects
None yet
Development

No branches or pull requests

3 participants