Is it possible to don't use Email to register and login in asp.net core identity?
Users just register by mobile number and login by SMS verification.
One possible way is to setup identity as two factor authentication. Instead of email use username to store the mobile number. To do this set RequireUniqueEmail = false
in ApplicationUserManager.Create.
You'll need to add your own code to retrieve the number and validate it. Make sure it always has the same format as it should match the username.
In the code where the username is verified skip the password check (since password is null), but do check the number. Send an SMS with code and continue with the flow.
You can add your own logic to create and verify the code and how long it is valid.
If you don't rely in Username
in your application, (Like you don't show it to user ever), then you can set Username to a guid and skip the email part.
For registration,
var identityUser = new User
{
Username= Guid.NewGuid(),
PhoneNumber= phoneNumber
};
var result = await _signInManager.UserManager.CreateAsync(identityUser, user.Password);
For Login,
var user = await _signInManager.UserManager.Users
.SingleOrDefaultAsync(x =>
x.NormalizedEmail == usernameParam
|| x.PhoneNumber== usernameParam);
if (user == null)
{
return Forbid();
}
var result = await _signInManager.CheckPasswordSignInAsync(user, passwordParam, false);
if (result.Succeeded)
{
// return new TokenResponse(token, refreshToken);
}