when I use this code:
var passwordHasher = new PasswordHasher();
string hashedPassword = passwordHasher.HashPassword(pp.Password);
User newUser = new User()
{
UserName = pp.NationalCode,
Pcode = pp.Pcode,
PasswordHash = hashedPassword,
};
var result = _UserManager.CreateAsync(newUser).Result;
the result will be succeeded, but if I use below code
User newUser = new User()
{
UserName = pp.NationalCode,
Pcode = pp.Pcode,
};
var result = _UserManager.CreateAsync(newUser,pp.Pasword).Result;
Result will be false.
On the other hand, because the password that is not systematically generated by Identity Hash, I can not use it in the login of users because (probably and certainly) the algorithms are different.
my codes in Login are :
if (ModelState.IsValid)
{
var user = _UserManager.FindByNameAsync(lc.UserName).Result;
_SignInManager.SignOutAsync();
if (user != null)
{
var result =await _SignInManager.PasswordSignInAsync(user,lc.Password, lc.IsPersistent, false);
if (result.Succeeded)
{
TempData["LoggedUserCode"] = user.Pcode;
return RedirectToAction("Index", "Home");
}
}
ModelState.AddModelError("", "Invalid User or Password");
}
The problem was solved with the help of an expert friend. In customizing the user table, I had mistakenly added a password field, which I removed it and the problem of adding new user solved. Also, the post action was defined as async, I removed async and the login problem solved.