Reputation: 352
I have a question, I have Web Application on Asp Net Core 1.1.0 with the implemented classical Identity model, and OpenIddict for Authorization.
In the classical implementation when registering the user using email / password, I need to realize the possibility of registering also with CodeNumber (numerical sequence length of 15 characters) as login name, and pin code (numeric combination of 4 characters) as a password.
CodeNumber and PinCode will be stored in separate from User Indentity table.
So that users can use two methods to log on to the system
Tell me please how can this be achieved in Asp .Net Core? Thank you in advance.
Upvotes: 1
Views: 245
Reputation: 239430
Simplistically, the way Identity works out of the box is that the user is queried by username and then signed in automatically by comparing the password. To handle things a different way, you just need to take more manual control over that process. Instead of using something like UserManager.FindByNameAsync
, you'd simply fallback to your context and do something like:
var user = db.Users.Where(m => m.CodeNumber == model.CodeNumber && m.PinCode == model.PinCode);
if (user == null)
{
ModelState.AddModelError("", "Incorrect code number and/or pin code");
}
Then, just sign the user in manually, if they exist:
await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
Upvotes: 1