We have customized Asp.Net Core to use our table of students rather than the AspNetUser table. Everything works fine for new students. But we need to update the existing students' passwords. I would like to do something like this (in AccountController Login method) when a student logins or this could be done on a one-time basis…
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Login(LoginViewModel model, string returnUrl = null)
{
ViewData["ReturnUrl"] = returnUrl;
if (ModelState.IsValid)
{
// Require the user to have a confirmed email before they can log on.
var user = await _userManager.FindByEmailAsync(model.Email);
if (user != null)
{
if (user.PasswordHash == null)
{
user.EmailConfirmed = true;
user.UserName = model.Email;
user.NormalizedEmail = model.Email.ToUpper();
user.NormalizedUserName = user.NormalizedEmail;
//user.PasswordHash = ?;
//user.SecurityStamp = ?;
//update user in database.
}
//continue on with login process
}
}
}
The below code (from the Register method) creates a new user and adds him to the database. This is not what we want.
var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
var result = await _userManager.CreateAsync(user, model.Password);
if (result.Succeeded)
// …
null? What password would the user use then, and how would you check that it’s the actual user?