Last post Jun 29, 2020 11:56 AM by EnenDaveyBoy
Jun 29, 2020 01:10 AM|laolaolulu|LINK
var result = await _signInManager.PasswordSignInAsync(UserName, Password, RememberMe, lockoutOnFailure: false);
I want to pass in the phonenumber in the username parameter
Jun 29, 2020 07:23 AM|Evern|LINK
You can login via phonenumber or email because the PasswordSignInAsync method has two overrides.
public virtual Task<SignInResult> PasswordSignInAsync(string userName, string password, bool isPersistent, bool lockoutOnFailure);
public virtual Task<SignInResult> PasswordSignInAsync(TUser user, string password, bool isPersistent, bool lockoutOnFailure);
Iterate through existing users in the UserManager with email and phonenumber. For example:
public async Task<IActionResult> Login(string email, string password)
var user = await _userManager.FindByEmailAsync(email);
if (user != null)
var signInResult = await _signInManager.PasswordSignInAsync(user, password, false, false);
Jun 29, 2020 07:53 AM|Sean Fang|LINK
I understand that you might want to login within either email or phone number in "username" textbox and password in "password" textbox.
However, from SignInManager level, the phone number might not be supported as it is a kind of custom user data and not under consideration of the SignInManger design.
The most common way to use phone number in identity is Two-factor authentication (2FA) which uses phone number to fetch short message code. You could refer to this: Two-factor
authentication with SMS in ASP.NET Core to learn how to integrate SMS in your project.
Regarding the "email" property, if you treat the email as the user name in user's registration, you could directly pass the value of "email" as the parameter "UserName" calling the below method.
If you do have "email" and "username" at the same time, you could use an overload method of PassPasswordSignInAsync: PassPasswordSignInAsync(TUser, String, Boolean, Boolean), which is able to take IdentityUser as parameter.
Before that, you have to find the IdentityUser by using below codes.
var currentUser= await _userManager.FindByEmailAsync(String email);
var result = await _signInManager.PasswordSignInAsync(currentUser, Password, RememberMe, lockoutOnFailure: false);
Note that it is recommended that you make the Email field unique.
If you already have set up a project within the identity, you could post the codes in this thread.
It would be easier to help you solve the problem in a certain scenario.
Hope this can help you.
Jun 29, 2020 11:56 AM|EnenDaveyBoy|LINK
there is no validation in identity to ensure that the phone number is unique, so you couldn't do it out of the box.
but you could download the source code and alter it, adding phone validation and changing the lookup to check of email and phone number.