On an ASP.NET Core 1.1 application with ASP.NET Identity I created a user:
PasswordHasher<User> hasher = new PasswordHasher<User>();
User user = new User {
Email = "john@company.com",
Username = "john@company.com
};
user.PasswordHash = hasher.HashPassword(user, "johnpass");
context.Users.Add(user);
context.SaveChanges();
The user is created but when I try to sign using the following it fails:
SignInResult result = await _signInManager.PasswordSignInAsync("john@company.com", "johnpass", false, true);
I then tried to create the user using the UserManager:
PasswordHasher<User> hasher = new PasswordHasher<User>();
User user = new User {
Email = "john@company.com",
Username = "john@company.com
};
await userManager.CreateAsync(user, "johnpass");
Now I am able to sign in. It seems the problem is with HashPassword method.
Does anyone knows how to create the user without UserManager?
UPDATE
I tried to create a UserManager without reeling on Injection because I am creating my test data on a Console Application and not on the Web Application:
var userStore = new UserStore(Context);
var userManager = new UserManager<User>(userStore, null, null, null, null, null, null, null, null);
The user is created but I am still not able to sign in.