Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

ASp.NET Core 2.0 Change Password not working

$
0
0

Hi,

The following code does not signed-in the user after a successful change password.


TEST 1
ApplicationUser user = await userManager.FindByIdAsync(userId);
user.PasswordHash = userManager.PasswordHasher.HashPassword(user, newPassword);
var result = await userManager.UpdateAsync(user);
if (result.Succeeded) //<<--GOOD return TRUE


TEST 2
ApplicationUser user = await userManager.FindByIdAsync(userId);
var token = userManager.GeneratePasswordResetTokenAsync(user).Result;
var result = userManager.ResetPasswordAsync(user, token, newPassword).Result;
if (result.Succeeded) //<<--GOOD return TRUE

TEST 3
ApplicationUser user = await userManager.FindByIdAsync(userId);
var resultRemove = await userManager.RemovePasswordAsync(user);
if (resultRemove.Succeeded)
{
var result = await userManager.AddPasswordAsync(user, newPassword);

if (result.Succeeded) //<<--GOOD return TRUE

After testing each Test above then do PasswordSignIn afterwards, the user is not signed-in. 

AccountController
var result = await _signInManager.PasswordSignInAsync(model.Email, model.Password, true, lockoutOnFailure: false);
if (result.Succeeded) //<<--ALWAYS FALSE

Startup.cs

services.Configure<IdentityOptions>(options =>
{
// Password settings
options.Password.RequireDigit = false;
options.Password.RequiredLength = 1;
options.Password.RequiredUniqueChars = 0;
options.Password.RequireNonAlphanumeric = false;
options.Password.RequireUppercase = false;
options.Password.RequireLowercase = false;

// User settings
options.User.RequireUniqueEmail = true;
});

Thanks,


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>